@ar.io/sdk
Version:
[](https://codecov.io/gh/ar-io/ar-io-sdk)
151 lines (150 loc) • 6.92 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.AntInfoSchema = exports.AntHandlersSchema = exports.AntHandlerNames = exports.AntWriteHandlers = exports.AntReadHandlers = exports.SpawnANTStateSchema = exports.AntStateSchema = exports.AntBalancesSchema = exports.AntControllersSchema = exports.AntRecordsSchema = exports.AntRecordSchema = exports.AntKeywordsSchema = exports.AntDescriptionSchema = exports.IntegerStringSchema = exports.AOAddressSchema = exports.ArweaveTxIdSchema = void 0;
exports.isAoANTState = isAoANTState;
/**
* 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 zod_1 = require("zod");
const constants_js_1 = require("../constants.js");
/**
* example error:
* {
"code": "custom",
"message": "Must be an Arweave Transaction ID",
"path": [
"Records",
"record1",
"transactionId"
]
},
*/
exports.ArweaveTxIdSchema = zod_1.z
.string({
description: 'Arweave Transaction ID',
})
.refine((val) => constants_js_1.ARWEAVE_TX_REGEX.test(val), {
message: 'Must be an Arweave Transaction ID',
});
exports.AOAddressSchema = zod_1.z.string({
description: 'AO Address',
});
exports.IntegerStringSchema = zod_1.z
.string({
description: 'Integer String',
})
.refine((val) => {
const num = parseInt(val);
return Number.isInteger(num) && num >= 0;
}, { message: 'Must be a non negative integer string' });
exports.AntDescriptionSchema = zod_1.z.string(); // TODO: add specific limits for description ie max length
exports.AntKeywordsSchema = zod_1.z.array(zod_1.z.string()); // TODO: add specific limits for keywords ie max amount and max length
exports.AntRecordSchema = zod_1.z.object({
transactionId: exports.ArweaveTxIdSchema.describe('The Target ID of the undername'),
ttlSeconds: zod_1.z.number(),
priority: zod_1.z.number().optional(),
});
exports.AntRecordsSchema = zod_1.z.record(zod_1.z.string(), exports.AntRecordSchema);
exports.AntControllersSchema = zod_1.z.array(exports.AOAddressSchema.describe('Controller address'));
exports.AntBalancesSchema = zod_1.z.record(exports.AOAddressSchema.describe('Holder address'), zod_1.z.number());
exports.AntStateSchema = zod_1.z.object({
Name: zod_1.z.string().describe('The name of the ANT.'),
Ticker: zod_1.z.string().describe('The ticker symbol for the ANT.'),
Description: zod_1.z.string().describe('The description for the ANT.'),
Keywords: exports.AntKeywordsSchema.describe('The keywords for the ANT.'),
Denomination: zod_1.z
.number()
.describe('The number of decimal places to use for the ANT. Defaults to 0 if not set representing whole numbers.')
.min(0, { message: 'Denomination must be a non-negative number' }),
Owner: exports.AOAddressSchema.describe('The Owners address.'),
Controllers: exports.AntControllersSchema.describe('Controllers of the ANT who have administrative privileges.'),
Records: exports.AntRecordsSchema.describe('Records associated with the ANT.'),
Balances: exports.AntBalancesSchema.describe('Balance details for each address holding the ANT.'),
Logo: exports.ArweaveTxIdSchema.describe('Transaction ID of the ANT logo.'),
TotalSupply: zod_1.z
.number()
.describe('Total supply of the ANT in circulation.')
.min(0, { message: 'Total supply must be a non-negative number' }),
Initialized: zod_1.z
.boolean()
.describe('Flag indicating whether the ANT has been initialized.'),
});
exports.SpawnANTStateSchema = zod_1.z.object({
name: zod_1.z.string().describe('The name of the ANT.'),
ticker: zod_1.z.string().describe('The ticker symbol for the ANT.'),
description: zod_1.z.string().describe('The description for the ANT.'),
keywords: exports.AntKeywordsSchema.describe('The keywords for the ANT.'),
owner: exports.AOAddressSchema.describe('The Owners address.'),
controllers: exports.AntControllersSchema.describe('Controllers of the ANT who have administrative privileges.'),
records: exports.AntRecordsSchema.describe('Records associated with the ANT.'),
balances: exports.AntBalancesSchema.describe('Balance details for each address holding the ANT.'),
logo: exports.ArweaveTxIdSchema.describe('Transaction ID of the ANT logo.'),
});
exports.AntReadHandlers = [
'balance',
'balances',
'totalSupply',
'info',
'controllers',
'record',
'records',
'state',
];
exports.AntWriteHandlers = [
'_eval',
'_default',
'transfer',
'addController',
'removeController',
'setRecord',
'removeRecord',
'setName',
'setTicker',
'setDescription',
'setKeywords',
'setLogo',
'initializeState',
'releaseName',
'reassignName',
'approvePrimaryName',
'removePrimaryNames',
];
exports.AntHandlerNames = [...exports.AntReadHandlers, ...exports.AntWriteHandlers];
exports.AntHandlersSchema = zod_1.z
.array(zod_1.z.string({ description: 'Handler Name' }))
.refine((antHandlers) => {
return exports.AntHandlerNames.every((handler) => antHandlers.includes(handler));
}, {
message: 'ANT is missing required handlers',
});
exports.AntInfoSchema = zod_1.z.object({
Name: zod_1.z.string().describe('The name of the ANT.'),
Owner: exports.ArweaveTxIdSchema.describe('The Owners address.'),
Ticker: zod_1.z.string().describe('The ticker symbol for the ANT.'),
['Total-Supply']: exports.IntegerStringSchema.describe('Total supply of the ANT in circulation.'),
Description: exports.AntDescriptionSchema.describe('The description for the ANT.'),
Keywords: exports.AntKeywordsSchema.describe('The keywords for the ANT.'),
Logo: exports.ArweaveTxIdSchema.describe('Transaction ID of the ANT logo.'),
Denomination: exports.IntegerStringSchema.describe('The number of decimal places to use for the ANT. Defaults to 0 if not set representing whole numbers.'),
Handlers: exports.AntHandlersSchema.optional().describe('List of handlers for the ANT.'),
HandlerNames: exports.AntHandlersSchema.optional().describe('Deprecated: List of handlers for the ANT. Use "Handlers" instead.'),
});
/**
* @param state {object}
* @returns {boolean}
*/
function isAoANTState(state) {
return exports.AntStateSchema.safeParse(state).success;
}
;