@defuse-protocol/intents-sdk 0.48.0 → 0.49.0
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/dist/src/intents/expirable-nonce.cjs +11 -3
- package/dist/src/intents/expirable-nonce.d.cts +10 -1
- package/dist/src/intents/expirable-nonce.d.ts +11 -1
- package/dist/src/intents/expirable-nonce.js +11 -3
- package/dist/src/intents/intent-hashes/ton-connect.cjs +0 -4
- package/dist/src/intents/intent-hashes/ton-connect.js +0 -4
- package/dist/src/intents/intent-payload-builder.cjs +26 -4
- package/dist/src/intents/intent-payload-builder.d.cts +21 -2
- package/dist/src/intents/intent-payload-builder.d.ts +21 -2
- package/dist/src/intents/intent-payload-builder.js +27 -5
- package/dist/src/intents/intent-payload-factory.cjs +0 -1
- package/dist/src/intents/intent-payload-factory.js +1 -1
- package/dist/src/intents/salt-manager.cjs +21 -1
- package/dist/src/intents/salt-manager.js +20 -1
- package/dist/src/sdk.cjs +1 -1
- package/dist/src/sdk.js +2 -2
- package/package.json +3 -3
|
@@ -53,14 +53,22 @@ const SALTED_NONCE_BORSH_SCHEMA = { struct: {
|
|
|
53
53
|
} };
|
|
54
54
|
let VersionedNonceBuilder;
|
|
55
55
|
(function(_VersionedNonceBuilder) {
|
|
56
|
-
|
|
56
|
+
const RANDOM_BYTES_LENGTH = 15;
|
|
57
|
+
function createTimestampedNonceBytes(startTime) {
|
|
58
|
+
const bytes = new Uint8Array(RANDOM_BYTES_LENGTH);
|
|
59
|
+
new DataView(bytes.buffer).setBigInt64(0, BigInt(startTime.getTime()) * 1000000n, true);
|
|
60
|
+
crypto.getRandomValues(bytes.subarray(8));
|
|
61
|
+
return bytes;
|
|
62
|
+
}
|
|
63
|
+
_VersionedNonceBuilder.createTimestampedNonceBytes = createTimestampedNonceBytes;
|
|
64
|
+
function encodeNonce(salt, deadline, randomBytes = crypto.getRandomValues(new Uint8Array(RANDOM_BYTES_LENGTH))) {
|
|
57
65
|
if (salt.length !== 4) throw new Error(`Invalid salt length: ${salt.length}, expected 4`);
|
|
66
|
+
if (randomBytes.length !== RANDOM_BYTES_LENGTH) throw new Error(`Invalid randomBytes length: ${randomBytes.length}, expected ${RANDOM_BYTES_LENGTH}`);
|
|
58
67
|
const deadlineBigInt = BigInt(deadline.getTime()) * 1000000n;
|
|
59
|
-
const nonceBytes = crypto.getRandomValues(new Uint8Array(15));
|
|
60
68
|
const borshBytes = new Uint8Array(27);
|
|
61
69
|
borshBytes.set(salt, 0);
|
|
62
70
|
new DataView(borshBytes.buffer, borshBytes.byteOffset, borshBytes.byteLength).setBigUint64(4, deadlineBigInt, true);
|
|
63
|
-
borshBytes.set(
|
|
71
|
+
borshBytes.set(randomBytes, 12);
|
|
64
72
|
const result = new Uint8Array(5 + borshBytes.length);
|
|
65
73
|
result.set(VERSIONED_MAGIC_PREFIX, 0);
|
|
66
74
|
result.set([LATEST_VERSION], 4);
|
|
@@ -24,14 +24,23 @@ declare class VersionedNonce {
|
|
|
24
24
|
static latest(saltedNonce: SaltedNonce): VersionedNonce;
|
|
25
25
|
}
|
|
26
26
|
declare namespace VersionedNonceBuilder {
|
|
27
|
+
/**
|
|
28
|
+
* Creates nonce bytes with embedded start timestamp.
|
|
29
|
+
* Layout: [startTime: 8 bytes LE nanoseconds] [random: 7 bytes]
|
|
30
|
+
*
|
|
31
|
+
* @param startTime The start time to embed in the nonce
|
|
32
|
+
* @returns 15-byte Uint8Array with timestamp and random data
|
|
33
|
+
*/
|
|
34
|
+
function createTimestampedNonceBytes(startTime: Date): Uint8Array;
|
|
27
35
|
/**
|
|
28
36
|
* Encodes a versioned expirable nonce with the given salt and deadline
|
|
29
37
|
*
|
|
30
38
|
* @param salt The salt to use for the nonce
|
|
31
39
|
* @param deadline The expiration deadline for the nonce
|
|
40
|
+
* @param randomBytes Optional random bytes to use. If not provided, random bytes will be generated.
|
|
32
41
|
* @returns The encoded nonce as a base64 string
|
|
33
42
|
*/
|
|
34
|
-
function encodeNonce(salt: Salt, deadline: Date): string;
|
|
43
|
+
function encodeNonce(salt: Salt, deadline: Date, randomBytes?: Uint8Array<ArrayBufferLike>): string;
|
|
35
44
|
/**
|
|
36
45
|
* Decodes a versioned expirable nonce from a base64-encoded string
|
|
37
46
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "valibot";
|
|
2
|
+
import "near-api-js/lib/utils/serialize";
|
|
2
3
|
|
|
3
4
|
//#region src/intents/expirable-nonce.d.ts
|
|
4
5
|
type Salt = Uint8Array;
|
|
@@ -25,14 +26,23 @@ declare class VersionedNonce {
|
|
|
25
26
|
static latest(saltedNonce: SaltedNonce): VersionedNonce;
|
|
26
27
|
}
|
|
27
28
|
declare namespace VersionedNonceBuilder {
|
|
29
|
+
/**
|
|
30
|
+
* Creates nonce bytes with embedded start timestamp.
|
|
31
|
+
* Layout: [startTime: 8 bytes LE nanoseconds] [random: 7 bytes]
|
|
32
|
+
*
|
|
33
|
+
* @param startTime The start time to embed in the nonce
|
|
34
|
+
* @returns 15-byte Uint8Array with timestamp and random data
|
|
35
|
+
*/
|
|
36
|
+
function createTimestampedNonceBytes(startTime: Date): Uint8Array;
|
|
28
37
|
/**
|
|
29
38
|
* Encodes a versioned expirable nonce with the given salt and deadline
|
|
30
39
|
*
|
|
31
40
|
* @param salt The salt to use for the nonce
|
|
32
41
|
* @param deadline The expiration deadline for the nonce
|
|
42
|
+
* @param randomBytes Optional random bytes to use. If not provided, random bytes will be generated.
|
|
33
43
|
* @returns The encoded nonce as a base64 string
|
|
34
44
|
*/
|
|
35
|
-
function encodeNonce(salt: Salt, deadline: Date): string;
|
|
45
|
+
function encodeNonce(salt: Salt, deadline: Date, randomBytes?: Uint8Array<ArrayBufferLike>): string;
|
|
36
46
|
/**
|
|
37
47
|
* Decodes a versioned expirable nonce from a base64-encoded string
|
|
38
48
|
*
|
|
@@ -51,14 +51,22 @@ const SALTED_NONCE_BORSH_SCHEMA = { struct: {
|
|
|
51
51
|
} };
|
|
52
52
|
let VersionedNonceBuilder;
|
|
53
53
|
(function(_VersionedNonceBuilder) {
|
|
54
|
-
|
|
54
|
+
const RANDOM_BYTES_LENGTH = 15;
|
|
55
|
+
function createTimestampedNonceBytes(startTime) {
|
|
56
|
+
const bytes = new Uint8Array(RANDOM_BYTES_LENGTH);
|
|
57
|
+
new DataView(bytes.buffer).setBigInt64(0, BigInt(startTime.getTime()) * 1000000n, true);
|
|
58
|
+
crypto.getRandomValues(bytes.subarray(8));
|
|
59
|
+
return bytes;
|
|
60
|
+
}
|
|
61
|
+
_VersionedNonceBuilder.createTimestampedNonceBytes = createTimestampedNonceBytes;
|
|
62
|
+
function encodeNonce(salt, deadline, randomBytes = crypto.getRandomValues(new Uint8Array(RANDOM_BYTES_LENGTH))) {
|
|
55
63
|
if (salt.length !== 4) throw new Error(`Invalid salt length: ${salt.length}, expected 4`);
|
|
64
|
+
if (randomBytes.length !== RANDOM_BYTES_LENGTH) throw new Error(`Invalid randomBytes length: ${randomBytes.length}, expected ${RANDOM_BYTES_LENGTH}`);
|
|
56
65
|
const deadlineBigInt = BigInt(deadline.getTime()) * 1000000n;
|
|
57
|
-
const nonceBytes = crypto.getRandomValues(new Uint8Array(15));
|
|
58
66
|
const borshBytes = new Uint8Array(27);
|
|
59
67
|
borshBytes.set(salt, 0);
|
|
60
68
|
new DataView(borshBytes.buffer, borshBytes.byteOffset, borshBytes.byteLength).setBigUint64(4, deadlineBigInt, true);
|
|
61
|
-
borshBytes.set(
|
|
69
|
+
borshBytes.set(randomBytes, 12);
|
|
62
70
|
const result = new Uint8Array(5 + borshBytes.length);
|
|
63
71
|
result.set(VERSIONED_MAGIC_PREFIX, 0);
|
|
64
72
|
result.set([LATEST_VERSION], 4);
|
|
@@ -52,8 +52,6 @@ function parseTonAddress(addressString) {
|
|
|
52
52
|
* payload
|
|
53
53
|
* )
|
|
54
54
|
*
|
|
55
|
-
* For cell payloads: Uses TON TLB message serialization (not fully implemented here)
|
|
56
|
-
*
|
|
57
55
|
* @param payload - The TON Connect payload to hash
|
|
58
56
|
* @returns 32-byte hash as Uint8Array
|
|
59
57
|
*/
|
|
@@ -86,8 +84,6 @@ function computeTonConnectHash(payload) {
|
|
|
86
84
|
}
|
|
87
85
|
return (0, _noble_hashes_sha2.sha256)(message);
|
|
88
86
|
}
|
|
89
|
-
case "binary": throw new Error("Binary payload hashing is not yet supported");
|
|
90
|
-
case "cell": throw new Error("Cell payload hashing is not yet supported.");
|
|
91
87
|
default: throw new Error(`Unknown TON Connect payload type: ${schemaType}`);
|
|
92
88
|
}
|
|
93
89
|
}
|
|
@@ -51,8 +51,6 @@ function parseTonAddress(addressString) {
|
|
|
51
51
|
* payload
|
|
52
52
|
* )
|
|
53
53
|
*
|
|
54
|
-
* For cell payloads: Uses TON TLB message serialization (not fully implemented here)
|
|
55
|
-
*
|
|
56
54
|
* @param payload - The TON Connect payload to hash
|
|
57
55
|
* @returns 32-byte hash as Uint8Array
|
|
58
56
|
*/
|
|
@@ -85,8 +83,6 @@ function computeTonConnectHash(payload) {
|
|
|
85
83
|
}
|
|
86
84
|
return sha256(message);
|
|
87
85
|
}
|
|
88
|
-
case "binary": throw new Error("Binary payload hashing is not yet supported");
|
|
89
|
-
case "cell": throw new Error("Cell payload hashing is not yet supported.");
|
|
90
86
|
default: throw new Error(`Unknown TON Connect payload type: ${schemaType}`);
|
|
91
87
|
}
|
|
92
88
|
}
|
|
@@ -92,8 +92,12 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
92
92
|
return this;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
* Set a
|
|
96
|
-
*
|
|
95
|
+
* Set a pre-built nonce directly.
|
|
96
|
+
* Use this when you have a complete nonce from an external source
|
|
97
|
+
* or need to reuse/invalidate a specific nonce.
|
|
98
|
+
*
|
|
99
|
+
* For most cases where you need custom random bytes, use {@link setNonceRandomBytes} instead,
|
|
100
|
+
* which handles salt fetching and nonce encoding automatically.
|
|
97
101
|
*
|
|
98
102
|
* @param nonce - Custom nonce string (base64 encoded)
|
|
99
103
|
* @returns The builder instance for chaining
|
|
@@ -103,6 +107,23 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
103
107
|
return this;
|
|
104
108
|
}
|
|
105
109
|
/**
|
|
110
|
+
* Set custom random bytes for nonce generation.
|
|
111
|
+
* The nonce will be automatically created at build time using these bytes,
|
|
112
|
+
* the deadline, and the contract salt.
|
|
113
|
+
*
|
|
114
|
+
* Use this when you need control over the random portion of the nonce
|
|
115
|
+
* (e.g., embedding a start timestamp via {@link VersionedNonceBuilder.createTimestampedNonceBytes}).
|
|
116
|
+
*
|
|
117
|
+
* For pre-built nonces, use {@link setNonce} instead.
|
|
118
|
+
*
|
|
119
|
+
* @param randomBytes - 15 bytes to use as the random portion of the nonce
|
|
120
|
+
* @returns The builder instance for chaining
|
|
121
|
+
*/
|
|
122
|
+
setNonceRandomBytes(randomBytes) {
|
|
123
|
+
this.customRandomBytes = randomBytes;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
106
127
|
* Clear all intents from the builder.
|
|
107
128
|
*
|
|
108
129
|
* @returns The builder instance for chaining
|
|
@@ -122,6 +143,7 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
122
143
|
this.deadline = void 0;
|
|
123
144
|
this.intents = [];
|
|
124
145
|
this.customNonce = void 0;
|
|
146
|
+
this.customRandomBytes = void 0;
|
|
125
147
|
this.verifyingContract = this.envConfig.contractID;
|
|
126
148
|
return this;
|
|
127
149
|
}
|
|
@@ -134,8 +156,7 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
134
156
|
*/
|
|
135
157
|
buildWithSalt(salt) {
|
|
136
158
|
const deadline = this.deadline ?? new Date(Date.now() + require_intent_payload_factory.DEFAULT_DEADLINE_MS);
|
|
137
|
-
const
|
|
138
|
-
const nonce = this.customNonce ?? require_expirable_nonce.VersionedNonceBuilder.encodeNonce(salt, nonceDeadline);
|
|
159
|
+
const nonce = this.customNonce ?? require_expirable_nonce.VersionedNonceBuilder.encodeNonce(salt, deadline, this.customRandomBytes);
|
|
139
160
|
return {
|
|
140
161
|
verifying_contract: this.verifyingContract,
|
|
141
162
|
signer_id: this.signerId,
|
|
@@ -184,6 +205,7 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
184
205
|
builder.deadline = this.deadline;
|
|
185
206
|
builder.intents = [...this.intents];
|
|
186
207
|
builder.customNonce = this.customNonce;
|
|
208
|
+
builder.customRandomBytes = this.customRandomBytes;
|
|
187
209
|
return builder;
|
|
188
210
|
}
|
|
189
211
|
/**
|
|
@@ -47,6 +47,7 @@ declare class IntentPayloadBuilder<HasSigner extends boolean = false> {
|
|
|
47
47
|
private deadline?;
|
|
48
48
|
private intents;
|
|
49
49
|
private customNonce?;
|
|
50
|
+
private customRandomBytes?;
|
|
50
51
|
constructor(config: IntentPayloadBuilderConfig);
|
|
51
52
|
/**
|
|
52
53
|
* Set the signer ID (address or account that will sign the intent).
|
|
@@ -89,13 +90,31 @@ declare class IntentPayloadBuilder<HasSigner extends boolean = false> {
|
|
|
89
90
|
*/
|
|
90
91
|
setVerifyingContract(contractAddress: string): this;
|
|
91
92
|
/**
|
|
92
|
-
* Set a
|
|
93
|
-
*
|
|
93
|
+
* Set a pre-built nonce directly.
|
|
94
|
+
* Use this when you have a complete nonce from an external source
|
|
95
|
+
* or need to reuse/invalidate a specific nonce.
|
|
96
|
+
*
|
|
97
|
+
* For most cases where you need custom random bytes, use {@link setNonceRandomBytes} instead,
|
|
98
|
+
* which handles salt fetching and nonce encoding automatically.
|
|
94
99
|
*
|
|
95
100
|
* @param nonce - Custom nonce string (base64 encoded)
|
|
96
101
|
* @returns The builder instance for chaining
|
|
97
102
|
*/
|
|
98
103
|
setNonce(nonce: string): this;
|
|
104
|
+
/**
|
|
105
|
+
* Set custom random bytes for nonce generation.
|
|
106
|
+
* The nonce will be automatically created at build time using these bytes,
|
|
107
|
+
* the deadline, and the contract salt.
|
|
108
|
+
*
|
|
109
|
+
* Use this when you need control over the random portion of the nonce
|
|
110
|
+
* (e.g., embedding a start timestamp via {@link VersionedNonceBuilder.createTimestampedNonceBytes}).
|
|
111
|
+
*
|
|
112
|
+
* For pre-built nonces, use {@link setNonce} instead.
|
|
113
|
+
*
|
|
114
|
+
* @param randomBytes - 15 bytes to use as the random portion of the nonce
|
|
115
|
+
* @returns The builder instance for chaining
|
|
116
|
+
*/
|
|
117
|
+
setNonceRandomBytes(randomBytes: Uint8Array<ArrayBufferLike>): this;
|
|
99
118
|
/**
|
|
100
119
|
* Clear all intents from the builder.
|
|
101
120
|
*
|
|
@@ -47,6 +47,7 @@ declare class IntentPayloadBuilder<HasSigner extends boolean = false> {
|
|
|
47
47
|
private deadline?;
|
|
48
48
|
private intents;
|
|
49
49
|
private customNonce?;
|
|
50
|
+
private customRandomBytes?;
|
|
50
51
|
constructor(config: IntentPayloadBuilderConfig);
|
|
51
52
|
/**
|
|
52
53
|
* Set the signer ID (address or account that will sign the intent).
|
|
@@ -89,13 +90,31 @@ declare class IntentPayloadBuilder<HasSigner extends boolean = false> {
|
|
|
89
90
|
*/
|
|
90
91
|
setVerifyingContract(contractAddress: string): this;
|
|
91
92
|
/**
|
|
92
|
-
* Set a
|
|
93
|
-
*
|
|
93
|
+
* Set a pre-built nonce directly.
|
|
94
|
+
* Use this when you have a complete nonce from an external source
|
|
95
|
+
* or need to reuse/invalidate a specific nonce.
|
|
96
|
+
*
|
|
97
|
+
* For most cases where you need custom random bytes, use {@link setNonceRandomBytes} instead,
|
|
98
|
+
* which handles salt fetching and nonce encoding automatically.
|
|
94
99
|
*
|
|
95
100
|
* @param nonce - Custom nonce string (base64 encoded)
|
|
96
101
|
* @returns The builder instance for chaining
|
|
97
102
|
*/
|
|
98
103
|
setNonce(nonce: string): this;
|
|
104
|
+
/**
|
|
105
|
+
* Set custom random bytes for nonce generation.
|
|
106
|
+
* The nonce will be automatically created at build time using these bytes,
|
|
107
|
+
* the deadline, and the contract salt.
|
|
108
|
+
*
|
|
109
|
+
* Use this when you need control over the random portion of the nonce
|
|
110
|
+
* (e.g., embedding a start timestamp via {@link VersionedNonceBuilder.createTimestampedNonceBytes}).
|
|
111
|
+
*
|
|
112
|
+
* For pre-built nonces, use {@link setNonce} instead.
|
|
113
|
+
*
|
|
114
|
+
* @param randomBytes - 15 bytes to use as the random portion of the nonce
|
|
115
|
+
* @returns The builder instance for chaining
|
|
116
|
+
*/
|
|
117
|
+
setNonceRandomBytes(randomBytes: Uint8Array<ArrayBufferLike>): this;
|
|
99
118
|
/**
|
|
100
119
|
* Clear all intents from the builder.
|
|
101
120
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VersionedNonceBuilder } from "./expirable-nonce.js";
|
|
2
|
-
import { DEFAULT_DEADLINE_MS
|
|
2
|
+
import { DEFAULT_DEADLINE_MS } from "./intent-payload-factory.js";
|
|
3
3
|
import { utils } from "@defuse-protocol/internal-utils";
|
|
4
4
|
|
|
5
5
|
//#region src/intents/intent-payload-builder.ts
|
|
@@ -91,8 +91,12 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
91
91
|
return this;
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
* Set a
|
|
95
|
-
*
|
|
94
|
+
* Set a pre-built nonce directly.
|
|
95
|
+
* Use this when you have a complete nonce from an external source
|
|
96
|
+
* or need to reuse/invalidate a specific nonce.
|
|
97
|
+
*
|
|
98
|
+
* For most cases where you need custom random bytes, use {@link setNonceRandomBytes} instead,
|
|
99
|
+
* which handles salt fetching and nonce encoding automatically.
|
|
96
100
|
*
|
|
97
101
|
* @param nonce - Custom nonce string (base64 encoded)
|
|
98
102
|
* @returns The builder instance for chaining
|
|
@@ -102,6 +106,23 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
102
106
|
return this;
|
|
103
107
|
}
|
|
104
108
|
/**
|
|
109
|
+
* Set custom random bytes for nonce generation.
|
|
110
|
+
* The nonce will be automatically created at build time using these bytes,
|
|
111
|
+
* the deadline, and the contract salt.
|
|
112
|
+
*
|
|
113
|
+
* Use this when you need control over the random portion of the nonce
|
|
114
|
+
* (e.g., embedding a start timestamp via {@link VersionedNonceBuilder.createTimestampedNonceBytes}).
|
|
115
|
+
*
|
|
116
|
+
* For pre-built nonces, use {@link setNonce} instead.
|
|
117
|
+
*
|
|
118
|
+
* @param randomBytes - 15 bytes to use as the random portion of the nonce
|
|
119
|
+
* @returns The builder instance for chaining
|
|
120
|
+
*/
|
|
121
|
+
setNonceRandomBytes(randomBytes) {
|
|
122
|
+
this.customRandomBytes = randomBytes;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
105
126
|
* Clear all intents from the builder.
|
|
106
127
|
*
|
|
107
128
|
* @returns The builder instance for chaining
|
|
@@ -121,6 +142,7 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
121
142
|
this.deadline = void 0;
|
|
122
143
|
this.intents = [];
|
|
123
144
|
this.customNonce = void 0;
|
|
145
|
+
this.customRandomBytes = void 0;
|
|
124
146
|
this.verifyingContract = this.envConfig.contractID;
|
|
125
147
|
return this;
|
|
126
148
|
}
|
|
@@ -133,8 +155,7 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
133
155
|
*/
|
|
134
156
|
buildWithSalt(salt) {
|
|
135
157
|
const deadline = this.deadline ?? new Date(Date.now() + DEFAULT_DEADLINE_MS);
|
|
136
|
-
const
|
|
137
|
-
const nonce = this.customNonce ?? VersionedNonceBuilder.encodeNonce(salt, nonceDeadline);
|
|
158
|
+
const nonce = this.customNonce ?? VersionedNonceBuilder.encodeNonce(salt, deadline, this.customRandomBytes);
|
|
138
159
|
return {
|
|
139
160
|
verifying_contract: this.verifyingContract,
|
|
140
161
|
signer_id: this.signerId,
|
|
@@ -183,6 +204,7 @@ var IntentPayloadBuilder = class IntentPayloadBuilder {
|
|
|
183
204
|
builder.deadline = this.deadline;
|
|
184
205
|
builder.intents = [...this.intents];
|
|
185
206
|
builder.customNonce = this.customNonce;
|
|
207
|
+
builder.customRandomBytes = this.customRandomBytes;
|
|
186
208
|
return builder;
|
|
187
209
|
}
|
|
188
210
|
/**
|
|
@@ -19,5 +19,4 @@ function defaultIntentPayloadFactory(salt, { intents, verifying_contract, ...par
|
|
|
19
19
|
|
|
20
20
|
//#endregion
|
|
21
21
|
exports.DEFAULT_DEADLINE_MS = DEFAULT_DEADLINE_MS;
|
|
22
|
-
exports.DEFAULT_NONCE_DEADLINE_OFFSET_MS = DEFAULT_NONCE_DEADLINE_OFFSET_MS;
|
|
23
22
|
exports.defaultIntentPayloadFactory = defaultIntentPayloadFactory;
|
|
@@ -6,6 +6,25 @@ valibot = require_rolldown_runtime.__toESM(valibot);
|
|
|
6
6
|
|
|
7
7
|
//#region src/intents/salt-manager.ts
|
|
8
8
|
const SALT_TTL_MS = 300 * 1e3;
|
|
9
|
+
/**
|
|
10
|
+
* Salt manager that returns a static, pre-configured salt.
|
|
11
|
+
* Use when salt is known ahead of time (e.g., private blockchain with fixed salt).
|
|
12
|
+
*/
|
|
13
|
+
var StaticSaltManager = class {
|
|
14
|
+
/**
|
|
15
|
+
* @param saltHex Salt as hex string (e.g., "01020304")
|
|
16
|
+
*/
|
|
17
|
+
constructor(saltHex) {
|
|
18
|
+
this.salt = _scure_base.hex.decode(saltHex);
|
|
19
|
+
if (this.salt.length !== 4) throw new Error(`Invalid salt length: ${this.salt.length}, expected 4`);
|
|
20
|
+
}
|
|
21
|
+
async getCachedSalt() {
|
|
22
|
+
return this.salt;
|
|
23
|
+
}
|
|
24
|
+
async refresh() {
|
|
25
|
+
return this.salt;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
9
28
|
var SaltManager = class {
|
|
10
29
|
constructor({ envConfig, nearProvider }) {
|
|
11
30
|
this.currentSalt = null;
|
|
@@ -71,4 +90,5 @@ async function fetchSalt(nearProvider, contractId) {
|
|
|
71
90
|
}
|
|
72
91
|
|
|
73
92
|
//#endregion
|
|
74
|
-
exports.SaltManager = SaltManager;
|
|
93
|
+
exports.SaltManager = SaltManager;
|
|
94
|
+
exports.StaticSaltManager = StaticSaltManager;
|
|
@@ -4,6 +4,25 @@ import * as v from "valibot";
|
|
|
4
4
|
|
|
5
5
|
//#region src/intents/salt-manager.ts
|
|
6
6
|
const SALT_TTL_MS = 300 * 1e3;
|
|
7
|
+
/**
|
|
8
|
+
* Salt manager that returns a static, pre-configured salt.
|
|
9
|
+
* Use when salt is known ahead of time (e.g., private blockchain with fixed salt).
|
|
10
|
+
*/
|
|
11
|
+
var StaticSaltManager = class {
|
|
12
|
+
/**
|
|
13
|
+
* @param saltHex Salt as hex string (e.g., "01020304")
|
|
14
|
+
*/
|
|
15
|
+
constructor(saltHex) {
|
|
16
|
+
this.salt = hex.decode(saltHex);
|
|
17
|
+
if (this.salt.length !== 4) throw new Error(`Invalid salt length: ${this.salt.length}, expected 4`);
|
|
18
|
+
}
|
|
19
|
+
async getCachedSalt() {
|
|
20
|
+
return this.salt;
|
|
21
|
+
}
|
|
22
|
+
async refresh() {
|
|
23
|
+
return this.salt;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
7
26
|
var SaltManager = class {
|
|
8
27
|
constructor({ envConfig, nearProvider }) {
|
|
9
28
|
this.currentSalt = null;
|
|
@@ -69,4 +88,4 @@ async function fetchSalt(nearProvider, contractId) {
|
|
|
69
88
|
}
|
|
70
89
|
|
|
71
90
|
//#endregion
|
|
72
|
-
export { SaltManager };
|
|
91
|
+
export { SaltManager, StaticSaltManager };
|
package/dist/src/sdk.cjs
CHANGED
|
@@ -84,7 +84,7 @@ var IntentsSDK = class {
|
|
|
84
84
|
solverRelayApiKey: this.solverRelayApiKey
|
|
85
85
|
});
|
|
86
86
|
this.intentSigner = args.intentSigner;
|
|
87
|
-
this.saltManager = new require_salt_manager.SaltManager({
|
|
87
|
+
this.saltManager = this.envConfig.contractSalt != null ? new require_salt_manager.StaticSaltManager(this.envConfig.contractSalt) : new require_salt_manager.SaltManager({
|
|
88
88
|
envConfig: this.envConfig,
|
|
89
89
|
nearProvider
|
|
90
90
|
});
|
package/dist/src/sdk.js
CHANGED
|
@@ -17,7 +17,7 @@ import { noopIntentSigner } from "./intents/intent-signer-impl/intent-signer-noo
|
|
|
17
17
|
import { zip } from "./lib/array.js";
|
|
18
18
|
import { configureEvmRpcUrls, configureStellarRpcUrls } from "./lib/configure-rpc-config.js";
|
|
19
19
|
import { createWithdrawalIdentifiers, watchWithdrawal } from "./core/withdrawal-watcher.js";
|
|
20
|
-
import { SaltManager } from "./intents/salt-manager.js";
|
|
20
|
+
import { SaltManager, StaticSaltManager } from "./intents/salt-manager.js";
|
|
21
21
|
import { IntentPayloadBuilder } from "./intents/intent-payload-builder.js";
|
|
22
22
|
import { PUBLIC_NEAR_RPC_URLS, RelayPublishError, assert, extractRpcUrls, nearFailoverRpcProvider, resolveEnvConfig, solverRelay } from "@defuse-protocol/internal-utils";
|
|
23
23
|
import { HotBridge } from "@hot-labs/omni-sdk";
|
|
@@ -82,7 +82,7 @@ var IntentsSDK = class {
|
|
|
82
82
|
solverRelayApiKey: this.solverRelayApiKey
|
|
83
83
|
});
|
|
84
84
|
this.intentSigner = args.intentSigner;
|
|
85
|
-
this.saltManager = new SaltManager({
|
|
85
|
+
this.saltManager = this.envConfig.contractSalt != null ? new StaticSaltManager(this.envConfig.contractSalt) : new SaltManager({
|
|
86
86
|
envConfig: this.envConfig,
|
|
87
87
|
nearProvider
|
|
88
88
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"ripple-address-codec": "^5.0.0",
|
|
48
48
|
"valibot": "^1.0.0",
|
|
49
49
|
"viem": "^2.0.0",
|
|
50
|
-
"@defuse-protocol/contract-types": "0.
|
|
51
|
-
"@defuse-protocol/internal-utils": "0.
|
|
50
|
+
"@defuse-protocol/contract-types": "0.6.0",
|
|
51
|
+
"@defuse-protocol/internal-utils": "0.26.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"tsdown": "0.19.0"
|