@ar.io/sdk
Version:
[](https://codecov.io/gh/ar-io/ar-io-sdk)
74 lines (73 loc) • 2.57 kB
JavaScript
/**
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ANT_REGISTRY_ID } from '../constants.js';
import { isProcessConfiguration, isProcessIdConfiguration, } from '../types/index.js';
import { createAoSigner } from '../utils/ao.js';
import { AOProcess, InvalidContractConfigurationError } from './index.js';
export class ANTRegistry {
static init(config) {
if (config !== undefined && 'signer' in config) {
return new AoANTRegistryWriteable(config);
}
return new AoANTRegistryReadable(config);
}
}
export class AoANTRegistryReadable {
process;
constructor(config) {
if (config === undefined || Object.keys(config).length === 0) {
this.process = new AOProcess({
processId: ANT_REGISTRY_ID,
});
}
else if (isProcessConfiguration(config)) {
this.process = config.process;
}
else if (isProcessIdConfiguration(config)) {
this.process = new AOProcess({
processId: config.processId,
});
}
else {
throw new InvalidContractConfigurationError();
}
}
// Should we rename this to "getANTsByAddress"? seems more clear, though not same as handler name
async accessControlList({ address, }) {
return this.process.read({
tags: [
{ name: 'Action', value: 'Access-Control-List' },
{ name: 'Address', value: address },
],
});
}
}
export class AoANTRegistryWriteable extends AoANTRegistryReadable {
signer;
constructor({ signer, ...config }) {
super(config);
this.signer = createAoSigner(signer);
}
async register({ processId, }) {
return this.process.send({
tags: [
{ name: 'Action', value: 'Register' },
{ name: 'Process-Id', value: processId },
],
signer: this.signer,
});
}
}