@ar.io/sdk 3.0.0 → 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.
- package/bundles/web.bundle.min.js +52 -52
- package/lib/cjs/common/contracts/ao-process.js +5 -0
- package/lib/cjs/utils/base64.js +10 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/contracts/ao-process.js +5 -0
- package/lib/esm/utils/base64.js +9 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/utils/base64.d.ts +1 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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({
|
package/lib/cjs/utils/base64.js
CHANGED
|
@@ -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;
|
package/lib/cjs/version.js
CHANGED
|
@@ -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({
|
package/lib/esm/utils/base64.js
CHANGED
|
@@ -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
|
+
}
|
package/lib/esm/version.js
CHANGED
package/lib/types/version.d.ts
CHANGED