@ar.io/sdk 3.0.0-alpha.1 → 3.0.1-alpha.1

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.
@@ -38,10 +38,10 @@ async function joinNetwork(options) {
38
38
  if (!options.skipConfirmation) {
39
39
  const settings = await ario.getGatewayRegistrySettings();
40
40
  if (settings.operators.minStake > mARIOQuantity.valueOf()) {
41
- throw new Error(`The minimum operator stake is ${(0, utils_js_1.formatARIOWithCommas)(new index_js_1.mARIOToken(settings.operators.minStake).toARIO())} IO. Please provide a higher stake.`);
41
+ throw new Error(`The minimum operator stake is ${(0, utils_js_1.formatARIOWithCommas)(new index_js_1.mARIOToken(settings.operators.minStake).toARIO())} ARIO. Please provide a higher stake.`);
42
42
  }
43
43
  await (0, utils_js_1.assertEnoughBalance)(ario, signerAddress, mARIOQuantity.toARIO());
44
- await (0, utils_js_1.assertConfirmationPrompt)(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${(0, utils_js_1.formatARIOWithCommas)(mARIOQuantity.toARIO())} IO to join the AR.IO network\nAre you sure?\n`, options);
44
+ await (0, utils_js_1.assertConfirmationPrompt)(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${(0, utils_js_1.formatARIOWithCommas)(mARIOQuantity.toARIO())} ARIO to join the AR.IO network\nAre you sure?\n`, options);
45
45
  }
46
46
  const result = await ario.joinNetwork(settings, (0, utils_js_1.writeActionTagsFromOptions)(options));
47
47
  const output = {
@@ -96,7 +96,7 @@ async function saveObservations(o) {
96
96
  exports.saveObservations = saveObservations;
97
97
  async function increaseOperatorStake(o) {
98
98
  const increaseQty = (0, utils_js_1.requiredMIOFromOptions)(o, 'operatorStake');
99
- await (0, utils_js_1.assertConfirmationPrompt)(`You are about to increase your operator stake by ${(0, utils_js_1.formatARIOWithCommas)(increaseQty.toARIO())} IO\nAre you sure?`, o);
99
+ await (0, utils_js_1.assertConfirmationPrompt)(`You are about to increase your operator stake by ${(0, utils_js_1.formatARIOWithCommas)(increaseQty.toARIO())} ARIO\nAre you sure?`, o);
100
100
  return ((0, utils_js_1.writeARIOFromOptions)(o).ario.increaseOperatorStake({
101
101
  increaseQty,
102
102
  }),
@@ -106,7 +106,7 @@ exports.increaseOperatorStake = increaseOperatorStake;
106
106
  async function decreaseOperatorStake(o) {
107
107
  const decreaseQty = (0, utils_js_1.requiredMIOFromOptions)(o, 'operatorStake');
108
108
  // TODO: Can assert stake is sufficient for action, and new target stake meets contract minimum
109
- await (0, utils_js_1.assertConfirmationPrompt)(`You are about to decrease your operator stake by ${(0, utils_js_1.formatARIOWithCommas)(decreaseQty.toARIO())} IO\nAre you sure?`, o);
109
+ await (0, utils_js_1.assertConfirmationPrompt)(`You are about to decrease your operator stake by ${(0, utils_js_1.formatARIOWithCommas)(decreaseQty.toARIO())} ARIO\nAre you sure?`, o);
110
110
  return (0, utils_js_1.writeARIOFromOptions)(o).ario.decreaseOperatorStake({
111
111
  decreaseQty,
112
112
  }, (0, utils_js_1.writeActionTagsFromOptions)(o));
@@ -65,7 +65,7 @@ exports.optionMap = {
65
65
  },
66
66
  quantity: {
67
67
  alias: '-q, --quantity <quantity>',
68
- description: 'The quantity of IO to interact with',
68
+ description: 'The quantity of ARIO to interact with',
69
69
  },
70
70
  autoStake: {
71
71
  alias: '--auto-stake',
@@ -296,15 +296,15 @@ function recordTypeFromOptions(options) {
296
296
  exports.recordTypeFromOptions = recordTypeFromOptions;
297
297
  function requiredMIOFromOptions(options, key) {
298
298
  if (options[key] === undefined) {
299
- throw new Error(`No ${key} provided. Use --${key} denominated in IO`);
299
+ throw new Error(`No ${key} provided. Use --${key} denominated in ARIO`);
300
300
  }
301
301
  return new index_js_1.ARIOToken(+options[key]).toMARIO();
302
302
  }
303
303
  exports.requiredMIOFromOptions = requiredMIOFromOptions;
304
- async function assertEnoughBalance(io, address, ioQuantity) {
305
- const balance = await io.getBalance({ address });
306
- if (balance < ioQuantity.toMARIO().valueOf()) {
307
- throw new Error(`Insufficient IO balance for action. Balance available: ${new index_js_1.mARIOToken(balance).toARIO()} IO`);
304
+ async function assertEnoughBalance(ario, address, arioQuantity) {
305
+ const balance = await ario.getBalance({ address });
306
+ if (balance < arioQuantity.toMARIO().valueOf()) {
307
+ throw new Error(`Insufficient ARIO balance for action. Balance available: ${new index_js_1.mARIOToken(balance).toARIO()} ARIO`);
308
308
  }
309
309
  }
310
310
  exports.assertEnoughBalance = assertEnoughBalance;
@@ -17,6 +17,7 @@ exports.AOProcess = void 0;
17
17
  * limitations under the License.
18
18
  */
19
19
  const aoconnect_1 = require("@permaweb/aoconnect");
20
+ const base64_js_1 = require("../../utils/base64.js");
20
21
  const json_js_1 = require("../../utils/json.js");
21
22
  const version_js_1 = require("../../version.js");
22
23
  const error_js_1 = require("../error.js");
@@ -89,16 +90,20 @@ class AOProcess {
89
90
  processId: this.processId,
90
91
  });
91
92
  // TODO: do a read as a dry run to check if the process supports the action
93
+ // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
94
+ const anchor = (0, base64_js_1.getRandomText)(32);
92
95
  const messageId = await this.ao.message({
93
96
  process: this.processId,
94
97
  // TODO: any other default tags we want to add?
95
98
  tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
96
99
  data,
97
100
  signer,
101
+ anchor,
98
102
  });
99
103
  this.logger.debug(`Sent message to process`, {
100
104
  messageId,
101
105
  processId: this.processId,
106
+ anchor,
102
107
  });
103
108
  // check the result of the send interaction
104
109
  const output = await this.ao.result({
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sha256B64Url = exports.toB64Url = exports.fromB64Url = void 0;
3
+ exports.getRandomText = exports.sha256B64Url = exports.toB64Url = exports.fromB64Url = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
6
  *
@@ -52,3 +52,12 @@ function sha256B64Url(input) {
52
52
  return toB64Url((0, crypto_1.createHash)('sha256').update(Uint8Array.from(input)).digest());
53
53
  }
54
54
  exports.sha256B64Url = sha256B64Url;
55
+ function getRandomText(length = 32) {
56
+ // Generate a buffer of random bytes
57
+ const buffer = (0, crypto_1.randomBytes)(length);
58
+ // Convert bytes to hexadecimal string
59
+ return Array.from(buffer, (byte) => byte.toString(16).padStart(2, '0'))
60
+ .join('')
61
+ .slice(0, length);
62
+ }
63
+ exports.getRandomText = getRandomText;
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.0.0-alpha.1';
20
+ exports.version = '3.0.1-alpha.1';
@@ -32,10 +32,10 @@ export async function joinNetwork(options) {
32
32
  if (!options.skipConfirmation) {
33
33
  const settings = await ario.getGatewayRegistrySettings();
34
34
  if (settings.operators.minStake > mARIOQuantity.valueOf()) {
35
- throw new Error(`The minimum operator stake is ${formatARIOWithCommas(new mARIOToken(settings.operators.minStake).toARIO())} IO. Please provide a higher stake.`);
35
+ throw new Error(`The minimum operator stake is ${formatARIOWithCommas(new mARIOToken(settings.operators.minStake).toARIO())} ARIO. Please provide a higher stake.`);
36
36
  }
37
37
  await assertEnoughBalance(ario, signerAddress, mARIOQuantity.toARIO());
38
- await assertConfirmationPrompt(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${formatARIOWithCommas(mARIOQuantity.toARIO())} IO to join the AR.IO network\nAre you sure?\n`, options);
38
+ await assertConfirmationPrompt(`Gateway Settings:\n\n${JSON.stringify(settings, null, 2)}\n\nYou are about to stake ${formatARIOWithCommas(mARIOQuantity.toARIO())} ARIO to join the AR.IO network\nAre you sure?\n`, options);
39
39
  }
40
40
  const result = await ario.joinNetwork(settings, writeActionTagsFromOptions(options));
41
41
  const output = {
@@ -86,7 +86,7 @@ export async function saveObservations(o) {
86
86
  }
87
87
  export async function increaseOperatorStake(o) {
88
88
  const increaseQty = requiredMARIOFromOptions(o, 'operatorStake');
89
- await assertConfirmationPrompt(`You are about to increase your operator stake by ${formatARIOWithCommas(increaseQty.toARIO())} IO\nAre you sure?`, o);
89
+ await assertConfirmationPrompt(`You are about to increase your operator stake by ${formatARIOWithCommas(increaseQty.toARIO())} ARIO\nAre you sure?`, o);
90
90
  return (writeARIOFromOptions(o).ario.increaseOperatorStake({
91
91
  increaseQty,
92
92
  }),
@@ -95,7 +95,7 @@ export async function increaseOperatorStake(o) {
95
95
  export async function decreaseOperatorStake(o) {
96
96
  const decreaseQty = requiredMARIOFromOptions(o, 'operatorStake');
97
97
  // TODO: Can assert stake is sufficient for action, and new target stake meets contract minimum
98
- await assertConfirmationPrompt(`You are about to decrease your operator stake by ${formatARIOWithCommas(decreaseQty.toARIO())} IO\nAre you sure?`, o);
98
+ await assertConfirmationPrompt(`You are about to decrease your operator stake by ${formatARIOWithCommas(decreaseQty.toARIO())} ARIO\nAre you sure?`, o);
99
99
  return writeARIOFromOptions(o).ario.decreaseOperatorStake({
100
100
  decreaseQty,
101
101
  }, writeActionTagsFromOptions(o));
@@ -62,7 +62,7 @@ export const optionMap = {
62
62
  },
63
63
  quantity: {
64
64
  alias: '-q, --quantity <quantity>',
65
- description: 'The quantity of IO to interact with',
65
+ description: 'The quantity of ARIO to interact with',
66
66
  },
67
67
  autoStake: {
68
68
  alias: '--auto-stake',
@@ -267,14 +267,14 @@ export function recordTypeFromOptions(options) {
267
267
  }
268
268
  export function requiredMIOFromOptions(options, key) {
269
269
  if (options[key] === undefined) {
270
- throw new Error(`No ${key} provided. Use --${key} denominated in IO`);
270
+ throw new Error(`No ${key} provided. Use --${key} denominated in ARIO`);
271
271
  }
272
272
  return new ARIOToken(+options[key]).toMARIO();
273
273
  }
274
- export async function assertEnoughBalance(io, address, ioQuantity) {
275
- const balance = await io.getBalance({ address });
276
- if (balance < ioQuantity.toMARIO().valueOf()) {
277
- throw new Error(`Insufficient IO balance for action. Balance available: ${new mARIOToken(balance).toARIO()} IO`);
274
+ export async function assertEnoughBalance(ario, address, arioQuantity) {
275
+ const balance = await ario.getBalance({ address });
276
+ if (balance < arioQuantity.toMARIO().valueOf()) {
277
+ throw new Error(`Insufficient ARIO balance for action. Balance available: ${new mARIOToken(balance).toARIO()} ARIO`);
278
278
  }
279
279
  }
280
280
  export async function confirmationPrompt(message) {
@@ -14,6 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { connect } from '@permaweb/aoconnect';
17
+ import { getRandomText } from '../../utils/base64.js';
17
18
  import { safeDecode } from '../../utils/json.js';
18
19
  import { version } from '../../version.js';
19
20
  import { WriteInteractionError } from '../error.js';
@@ -86,16 +87,20 @@ export class AOProcess {
86
87
  processId: this.processId,
87
88
  });
88
89
  // TODO: do a read as a dry run to check if the process supports the action
90
+ // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
91
+ const anchor = getRandomText(32);
89
92
  const messageId = await this.ao.message({
90
93
  process: this.processId,
91
94
  // TODO: any other default tags we want to add?
92
95
  tags: [...tags, { name: 'AR-IO-SDK', value: version }],
93
96
  data,
94
97
  signer,
98
+ anchor,
95
99
  });
96
100
  this.logger.debug(`Sent message to process`, {
97
101
  messageId,
98
102
  processId: this.processId,
103
+ anchor,
99
104
  });
100
105
  // check the result of the send interaction
101
106
  const output = await this.ao.result({
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { createHash } from 'crypto';
16
+ import { createHash, randomBytes } from 'crypto';
17
17
  // safely encodes and decodes base64url strings to and from buffers
18
18
  const BASE64_CHAR_62 = '+';
19
19
  const BASE64_CHAR_63 = '/';
@@ -46,3 +46,11 @@ export function toB64Url(buffer) {
46
46
  export function sha256B64Url(input) {
47
47
  return toB64Url(createHash('sha256').update(Uint8Array.from(input)).digest());
48
48
  }
49
+ export function getRandomText(length = 32) {
50
+ // Generate a buffer of random bytes
51
+ const buffer = randomBytes(length);
52
+ // Convert bytes to hexadecimal string
53
+ return Array.from(buffer, (byte) => byte.toString(16).padStart(2, '0'))
54
+ .join('')
55
+ .slice(0, length);
56
+ }
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.0.0-alpha.1';
17
+ export const version = '3.0.1-alpha.1';
@@ -52,7 +52,7 @@ export declare function recordTypeFromOptions<O extends {
52
52
  type?: string;
53
53
  }>(options: O): 'lease' | 'permabuy';
54
54
  export declare function requiredMIOFromOptions<O extends GlobalCLIOptions>(options: O, key: string): mARIOToken;
55
- export declare function assertEnoughBalance(io: AoARIORead, address: string, ioQuantity: ARIOToken): Promise<void>;
55
+ export declare function assertEnoughBalance(ario: AoARIORead, address: string, arioQuantity: ARIOToken): Promise<void>;
56
56
  export declare function confirmationPrompt(message: string): Promise<boolean>;
57
57
  export declare function assertConfirmationPrompt<O extends {
58
58
  skipConfirmation?: boolean;
@@ -2,3 +2,4 @@
2
2
  export declare function fromB64Url(str: string): Buffer;
3
3
  export declare function toB64Url(buffer: Buffer): string;
4
4
  export declare function sha256B64Url(input: Buffer): string;
5
+ export declare function getRandomText(length?: number): string;
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "2.7.0-alpha.7";
16
+ export declare const version = "3.0.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.1-alpha.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"