@ar.io/sdk 3.24.0 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +757 -589
  2. package/lib/esm/cli/cli.js +188 -152
  3. package/lib/esm/cli/commands/antCommands.js +23 -58
  4. package/lib/esm/cli/commands/arnsPurchaseCommands.js +48 -30
  5. package/lib/esm/cli/commands/escrowCommands.js +227 -0
  6. package/lib/esm/cli/commands/gatewayWriteCommands.js +140 -23
  7. package/lib/esm/cli/commands/pruneCommands.js +154 -0
  8. package/lib/esm/cli/commands/readCommands.js +22 -3
  9. package/lib/esm/cli/commands/transfer.js +6 -6
  10. package/lib/esm/cli/options.js +124 -58
  11. package/lib/esm/cli/utils.js +303 -175
  12. package/lib/esm/common/ant-registry.js +17 -143
  13. package/lib/esm/common/ant.js +44 -1167
  14. package/lib/esm/common/faucet.js +17 -6
  15. package/lib/esm/common/index.js +0 -4
  16. package/lib/esm/common/io.js +25 -1412
  17. package/lib/esm/constants.js +13 -19
  18. package/lib/esm/solana/ant-readable.js +724 -0
  19. package/lib/esm/solana/ant-registry-readable.js +133 -0
  20. package/lib/esm/solana/ant-registry-writeable.js +472 -0
  21. package/lib/esm/solana/ant-writeable.js +384 -0
  22. package/lib/esm/solana/ata.js +70 -0
  23. package/lib/esm/solana/canonical-message.js +128 -0
  24. package/lib/esm/solana/clusters.js +111 -0
  25. package/lib/esm/solana/constants.js +146 -0
  26. package/lib/esm/solana/delegation-math.js +112 -0
  27. package/lib/esm/solana/deserialize.js +711 -0
  28. package/lib/esm/solana/escrow.js +839 -0
  29. package/lib/{cjs/utils/json.js → esm/solana/events.js} +15 -10
  30. package/lib/esm/solana/funding-plan.js +699 -0
  31. package/lib/esm/solana/index.js +126 -0
  32. package/lib/esm/solana/instruction.js +39 -0
  33. package/lib/esm/solana/io-readable.js +2182 -0
  34. package/lib/esm/solana/io-writeable.js +3196 -0
  35. package/lib/esm/solana/json-rpc.js +90 -0
  36. package/lib/esm/solana/metadata.js +81 -0
  37. package/lib/esm/solana/mpl-core.js +192 -0
  38. package/lib/esm/solana/pda.js +332 -0
  39. package/lib/esm/solana/predict-prescribed-observers.js +110 -0
  40. package/lib/esm/solana/retry.js +117 -0
  41. package/lib/esm/solana/rpc-circuit-breaker.js +258 -0
  42. package/lib/esm/solana/send.js +372 -0
  43. package/lib/esm/solana/spawn-ant.js +224 -0
  44. package/lib/esm/solana/types.js +1 -0
  45. package/lib/esm/types/ant.js +27 -15
  46. package/lib/esm/types/io.js +8 -11
  47. package/lib/esm/utils/ant.js +0 -63
  48. package/lib/esm/utils/index.js +0 -3
  49. package/lib/esm/version.js +1 -1
  50. package/lib/types/cli/commands/antCommands.d.ts +5 -13
  51. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +33 -7
  52. package/lib/types/cli/commands/escrowCommands.d.ts +68 -0
  53. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +12 -11
  54. package/lib/types/cli/commands/pruneCommands.d.ts +31 -0
  55. package/lib/types/cli/commands/readCommands.d.ts +27 -22
  56. package/lib/types/cli/commands/transfer.d.ts +9 -9
  57. package/lib/types/cli/options.d.ts +76 -21
  58. package/lib/types/cli/types.d.ts +11 -13
  59. package/lib/types/cli/utils.d.ts +71 -31
  60. package/lib/types/common/ant-registry.d.ts +49 -47
  61. package/lib/types/common/ant.d.ts +54 -539
  62. package/lib/types/common/faucet.d.ts +20 -8
  63. package/lib/types/common/index.d.ts +0 -3
  64. package/lib/types/common/io.d.ts +66 -258
  65. package/lib/types/constants.d.ts +11 -18
  66. package/lib/types/solana/ant-readable.d.ts +180 -0
  67. package/lib/types/solana/ant-registry-readable.d.ts +105 -0
  68. package/lib/types/solana/ant-registry-writeable.d.ts +249 -0
  69. package/lib/types/solana/ant-writeable.d.ts +177 -0
  70. package/lib/types/solana/ata.d.ts +44 -0
  71. package/lib/types/solana/canonical-message.d.ts +121 -0
  72. package/lib/types/solana/clusters.d.ts +109 -0
  73. package/lib/types/solana/constants.d.ts +119 -0
  74. package/lib/types/solana/delegation-math.d.ts +45 -0
  75. package/lib/types/solana/deserialize.d.ts +262 -0
  76. package/lib/types/solana/escrow.d.ts +480 -0
  77. package/lib/types/solana/events.d.ts +38 -0
  78. package/lib/types/solana/funding-plan.d.ts +225 -0
  79. package/lib/types/solana/index.d.ts +87 -0
  80. package/lib/types/solana/instruction.d.ts +39 -0
  81. package/lib/types/solana/io-readable.d.ts +499 -0
  82. package/lib/types/solana/io-writeable.d.ts +893 -0
  83. package/lib/types/solana/json-rpc.d.ts +47 -0
  84. package/lib/types/solana/metadata.d.ts +84 -0
  85. package/lib/types/solana/mpl-core.d.ts +120 -0
  86. package/lib/types/solana/pda.d.ts +95 -0
  87. package/lib/types/solana/predict-prescribed-observers.d.ts +28 -0
  88. package/lib/types/solana/retry.d.ts +62 -0
  89. package/lib/types/solana/rpc-circuit-breaker.d.ts +78 -0
  90. package/lib/types/solana/send.d.ts +94 -0
  91. package/lib/types/solana/spawn-ant.d.ts +145 -0
  92. package/lib/types/solana/types.d.ts +82 -0
  93. package/lib/types/types/ant-registry.d.ts +43 -4
  94. package/lib/types/types/ant.d.ts +114 -96
  95. package/lib/types/types/common.d.ts +18 -74
  96. package/lib/types/types/faucet.d.ts +2 -2
  97. package/lib/types/types/io.d.ts +244 -158
  98. package/lib/types/types/token.d.ts +0 -12
  99. package/lib/types/utils/ant.d.ts +1 -12
  100. package/lib/types/utils/index.d.ts +0 -3
  101. package/lib/types/version.d.ts +1 -1
  102. package/package.json +36 -33
  103. package/lib/cjs/cli/cli.js +0 -822
  104. package/lib/cjs/cli/commands/antCommands.js +0 -113
  105. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +0 -212
  106. package/lib/cjs/cli/commands/gatewayWriteCommands.js +0 -210
  107. package/lib/cjs/cli/commands/readCommands.js +0 -215
  108. package/lib/cjs/cli/commands/transfer.js +0 -159
  109. package/lib/cjs/cli/options.js +0 -470
  110. package/lib/cjs/cli/types.js +0 -2
  111. package/lib/cjs/cli/utils.js +0 -639
  112. package/lib/cjs/common/ant-registry.js +0 -155
  113. package/lib/cjs/common/ant-versions.js +0 -93
  114. package/lib/cjs/common/ant.js +0 -1182
  115. package/lib/cjs/common/arweave.js +0 -27
  116. package/lib/cjs/common/contracts/ao-process.js +0 -224
  117. package/lib/cjs/common/error.js +0 -64
  118. package/lib/cjs/common/faucet.js +0 -150
  119. package/lib/cjs/common/hyperbeam/hb.js +0 -173
  120. package/lib/cjs/common/index.js +0 -42
  121. package/lib/cjs/common/io.js +0 -1423
  122. package/lib/cjs/common/logger.js +0 -83
  123. package/lib/cjs/common/loggers/winston.js +0 -68
  124. package/lib/cjs/common/marketplace.js +0 -731
  125. package/lib/cjs/common/turbo.js +0 -223
  126. package/lib/cjs/constants.js +0 -41
  127. package/lib/cjs/node/index.js +0 -39
  128. package/lib/cjs/package.json +0 -1
  129. package/lib/cjs/types/ant-registry.js +0 -2
  130. package/lib/cjs/types/ant.js +0 -168
  131. package/lib/cjs/types/common.js +0 -2
  132. package/lib/cjs/types/faucet.js +0 -2
  133. package/lib/cjs/types/index.js +0 -37
  134. package/lib/cjs/types/io.js +0 -51
  135. package/lib/cjs/types/token.js +0 -116
  136. package/lib/cjs/utils/ant.js +0 -108
  137. package/lib/cjs/utils/ao.js +0 -432
  138. package/lib/cjs/utils/arweave.js +0 -285
  139. package/lib/cjs/utils/base64.js +0 -62
  140. package/lib/cjs/utils/hash.js +0 -56
  141. package/lib/cjs/utils/index.js +0 -38
  142. package/lib/cjs/utils/processes.js +0 -173
  143. package/lib/cjs/utils/random.js +0 -30
  144. package/lib/cjs/utils/schema.js +0 -15
  145. package/lib/cjs/utils/url.js +0 -37
  146. package/lib/cjs/version.js +0 -20
  147. package/lib/cjs/web/index.js +0 -41
  148. package/lib/esm/common/ant-versions.js +0 -87
  149. package/lib/esm/common/arweave.js +0 -21
  150. package/lib/esm/common/contracts/ao-process.js +0 -220
  151. package/lib/esm/common/hyperbeam/hb.js +0 -169
  152. package/lib/esm/common/marketplace.js +0 -724
  153. package/lib/esm/common/turbo.js +0 -215
  154. package/lib/esm/node/index.js +0 -20
  155. package/lib/esm/utils/ao.js +0 -420
  156. package/lib/esm/utils/arweave.js +0 -271
  157. package/lib/esm/utils/processes.js +0 -167
  158. package/lib/esm/web/index.js +0 -20
  159. package/lib/types/common/ant-versions.d.ts +0 -39
  160. package/lib/types/common/arweave.d.ts +0 -17
  161. package/lib/types/common/contracts/ao-process.d.ts +0 -47
  162. package/lib/types/common/hyperbeam/hb.d.ts +0 -88
  163. package/lib/types/common/marketplace.d.ts +0 -568
  164. package/lib/types/common/turbo.d.ts +0 -61
  165. package/lib/types/node/index.d.ts +0 -20
  166. package/lib/types/utils/ao.d.ts +0 -80
  167. package/lib/types/utils/arweave.d.ts +0 -79
  168. package/lib/types/utils/processes.d.ts +0 -39
  169. package/lib/types/web/index.d.ts +0 -20
@@ -1,155 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AoANTRegistryWriteable = exports.AoANTRegistryReadable = exports.ANTRegistry = void 0;
4
- /**
5
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- const constants_js_1 = require("../constants.js");
20
- const index_js_1 = require("../types/index.js");
21
- const ao_js_1 = require("../utils/ao.js");
22
- const index_js_2 = require("./index.js");
23
- const logger_js_1 = require("./logger.js");
24
- class ANTRegistry {
25
- static init(config) {
26
- if (config !== undefined && 'signer' in config) {
27
- return new AoANTRegistryWriteable(config);
28
- }
29
- return new AoANTRegistryReadable(config);
30
- }
31
- }
32
- exports.ANTRegistry = ANTRegistry;
33
- class AoANTRegistryReadable {
34
- process;
35
- hyperbeamUrl;
36
- checkHyperBeamPromise;
37
- logger;
38
- constructor(config) {
39
- this.logger = config?.logger ?? logger_js_1.Logger.default;
40
- if (config === undefined || Object.keys(config).length === 0) {
41
- this.process = new index_js_2.AOProcess({
42
- processId: constants_js_1.ANT_REGISTRY_ID,
43
- });
44
- }
45
- else if ((0, index_js_1.isProcessConfiguration)(config)) {
46
- this.process = config.process;
47
- }
48
- else if ((0, index_js_1.isProcessIdConfiguration)(config)) {
49
- this.process = new index_js_2.AOProcess({
50
- processId: config.processId,
51
- });
52
- }
53
- else {
54
- throw new index_js_2.InvalidContractConfigurationError();
55
- }
56
- if (config?.hyperbeamUrl !== undefined) {
57
- this.hyperbeamUrl = new URL(config.hyperbeamUrl).toString();
58
- this.checkHyperBeamPromise = this.checkHyperBeamCompatibility();
59
- }
60
- }
61
- /**
62
- * Check if the process is HyperBeam compatible. If so, we'll use the HyperBeam node to fetch the state.
63
- *
64
- * @returns {Promise<boolean>} True if the process is HyperBeam compatible, false otherwise.
65
- */
66
- async checkHyperBeamCompatibility() {
67
- if (this.hyperbeamUrl === undefined) {
68
- return Promise.resolve(false);
69
- }
70
- if (this.checkHyperBeamPromise !== undefined) {
71
- return this.checkHyperBeamPromise;
72
- }
73
- this.logger.debug('Checking HyperBeam compatibility');
74
- this.checkHyperBeamPromise = fetch(
75
- // use /now to force a refresh of the cache state, then compute when calling it for keys
76
- `${this.hyperbeamUrl.toString()}${this.process.processId}~process@1.0/now/cache/acl`, {
77
- method: 'HEAD',
78
- signal: AbortSignal.timeout(5000), // 5 second timeout
79
- })
80
- .then((res) => {
81
- if (res.ok) {
82
- this.logger.debug('HyperBeam compatible');
83
- return true;
84
- }
85
- this.logger.debug('HyperBeam not compatible');
86
- return false;
87
- })
88
- .catch((error) => {
89
- this.logger.debug('Failed to check HyperBeam compatibility', {
90
- cause: error,
91
- });
92
- return false;
93
- });
94
- return this.checkHyperBeamPromise;
95
- }
96
- // Should we rename this to "getANTsByAddress"? seems more clear, though not same as handler name
97
- async accessControlList({ address, }) {
98
- if (await this.checkHyperBeamCompatibility()) {
99
- let retries = 0;
100
- while (retries < 3) {
101
- try {
102
- this.logger.debug('Fetching ant registry acl for address from hyperbeam', address);
103
- const res = await fetch(`${this.hyperbeamUrl?.toString()}${this.process.processId}~process@1.0/compute/cache/acl/${address}/serialize~json@1.0`);
104
- if (res.status !== 200) {
105
- this.logger.debug('Failed to fetch ant registry acl for address from hyperbeam', address, res.status, res.statusText);
106
- throw new Error(`Failed to fetch ant registry acl for address ${address}: ${res?.statusText ?? 'Unknown error'}`);
107
- }
108
- this.logger.debug('Fetched ant registry acl for address from hyperbeam', address);
109
- const json = (await res.json());
110
- return {
111
- Owned: json.Owned,
112
- Controlled: json.Controlled,
113
- };
114
- }
115
- catch (_error) {
116
- retries++;
117
- this.logger.debug('Failed to fetch ant registry acl for address from hyperbeam', address, retries);
118
- await new Promise((resolve) => setTimeout(resolve, 1000 * retries ** 2));
119
- }
120
- }
121
- }
122
- this.logger.debug('Fetching ant registry acl for address from process', address);
123
- return this.process.read({
124
- tags: [
125
- { name: 'Action', value: 'Access-Control-List' },
126
- { name: 'Address', value: address },
127
- ],
128
- });
129
- }
130
- /*
131
- * This is the same as accessControlList, but with a cleaner DX to make it clearer
132
- * that we're fetching the list of ANTs owned or controlled by an address.
133
- */
134
- async getAntsForAddress({ address, }) {
135
- return this.accessControlList({ address });
136
- }
137
- }
138
- exports.AoANTRegistryReadable = AoANTRegistryReadable;
139
- class AoANTRegistryWriteable extends AoANTRegistryReadable {
140
- signer;
141
- constructor({ signer, ...config }) {
142
- super(config);
143
- this.signer = (0, ao_js_1.createAoSigner)(signer);
144
- }
145
- async register({ processId, }) {
146
- return this.process.send({
147
- tags: [
148
- { name: 'Action', value: 'Register' },
149
- { name: 'Process-Id', value: processId },
150
- ],
151
- signer: this.signer,
152
- });
153
- }
154
- }
155
- exports.AoANTRegistryWriteable = AoANTRegistryWriteable;
@@ -1,93 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ANTVersionsWritable = exports.ANTVersionsReadable = exports.ANTVersions = void 0;
4
- /**
5
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- const constants_js_1 = require("../constants.js");
20
- const io_js_1 = require("../types/io.js");
21
- const ao_js_1 = require("../utils/ao.js");
22
- const arweave_js_1 = require("../utils/arweave.js");
23
- const ao_process_js_1 = require("./contracts/ao-process.js");
24
- const error_js_1 = require("./error.js");
25
- class ANTVersions {
26
- static init(config) {
27
- if (config !== undefined && 'signer' in config) {
28
- return new ANTVersionsWritable(config);
29
- }
30
- return new ANTVersionsReadable(config);
31
- }
32
- }
33
- exports.ANTVersions = ANTVersions;
34
- class ANTVersionsReadable {
35
- process;
36
- constructor(config) {
37
- if (config === undefined || Object.keys(config).length === 0) {
38
- this.process = new ao_process_js_1.AOProcess({
39
- processId: constants_js_1.ANT_REGISTRY_ID,
40
- });
41
- }
42
- else if ((0, io_js_1.isProcessConfiguration)(config)) {
43
- this.process = config.process;
44
- }
45
- else if ((0, io_js_1.isProcessIdConfiguration)(config)) {
46
- this.process = new ao_process_js_1.AOProcess({
47
- processId: config.processId,
48
- });
49
- }
50
- else {
51
- throw new error_js_1.InvalidContractConfigurationError();
52
- }
53
- }
54
- async getANTVersions() {
55
- const res = await this.process.read({
56
- tags: [{ name: 'Action', value: 'Get-Versions' }],
57
- });
58
- return Object.fromEntries(Object.entries(res).sort(([a], [b]) => a.localeCompare(b)));
59
- }
60
- async getLatestANTVersion() {
61
- const versions = await this.getANTVersions();
62
- const lastestVersion = Object.entries(versions).at(-1);
63
- if (!lastestVersion)
64
- throw new Error('No version found');
65
- return {
66
- version: lastestVersion[0],
67
- ...lastestVersion[1],
68
- };
69
- }
70
- }
71
- exports.ANTVersionsReadable = ANTVersionsReadable;
72
- class ANTVersionsWritable extends ANTVersionsReadable {
73
- signer;
74
- constructor({ signer, ...config }) {
75
- super(config);
76
- this.signer = (0, ao_js_1.createAoSigner)(signer);
77
- }
78
- async addVersion(params, options) {
79
- const { version, moduleId, luaSourceId, notes } = params;
80
- return this.process.send({
81
- tags: (0, arweave_js_1.pruneTags)([
82
- { name: 'Action', value: 'Add-Version' },
83
- { name: 'Version', value: version },
84
- { name: 'Module-Id', value: moduleId },
85
- { name: 'Lua-Source-Id', value: luaSourceId },
86
- { name: 'Notes', value: notes },
87
- ...(options?.tags ?? []),
88
- ]),
89
- signer: this.signer,
90
- });
91
- }
92
- }
93
- exports.ANTVersionsWritable = ANTVersionsWritable;