UNPKG

@ar.io/sdk

Version:

[![codecov](https://codecov.io/gh/ar-io/ar-io-sdk/graph/badge.svg?token=7dXKcT7dJy)](https://codecov.io/gh/ar-io/ar-io-sdk)

80 lines (79 loc) 2.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AoANTRegistryWriteable = exports.AoANTRegistryReadable = exports.ANTRegistry = void 0; /** * 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. */ const constants_js_1 = require("../constants.js"); const index_js_1 = require("../types/index.js"); const ao_js_1 = require("../utils/ao.js"); const index_js_2 = require("./index.js"); class ANTRegistry { static init(config) { if (config !== undefined && 'signer' in config) { return new AoANTRegistryWriteable(config); } return new AoANTRegistryReadable(config); } } exports.ANTRegistry = ANTRegistry; class AoANTRegistryReadable { process; constructor(config) { if (config === undefined || Object.keys(config).length === 0) { this.process = new index_js_2.AOProcess({ processId: constants_js_1.ANT_REGISTRY_ID, }); } else if ((0, index_js_1.isProcessConfiguration)(config)) { this.process = config.process; } else if ((0, index_js_1.isProcessIdConfiguration)(config)) { this.process = new index_js_2.AOProcess({ processId: config.processId, }); } else { throw new index_js_2.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 }, ], }); } } exports.AoANTRegistryReadable = AoANTRegistryReadable; class AoANTRegistryWriteable extends AoANTRegistryReadable { signer; constructor({ signer, ...config }) { super(config); this.signer = (0, ao_js_1.createAoSigner)(signer); } async register({ processId, }) { return this.process.send({ tags: [ { name: 'Action', value: 'Register' }, { name: 'Process-Id', value: processId }, ], signer: this.signer, }); } } exports.AoANTRegistryWriteable = AoANTRegistryWriteable;