@defuse-protocol/intents-sdk 0.36.0 → 0.36.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.
|
@@ -25,12 +25,6 @@ const saltedNonceSchema = valibot.object({
|
|
|
25
25
|
nonce: valibot.array(valibot.number())
|
|
26
26
|
})
|
|
27
27
|
});
|
|
28
|
-
var SaltedNonce = class {
|
|
29
|
-
constructor(salt, inner) {
|
|
30
|
-
this.salt = salt;
|
|
31
|
-
this.inner = inner;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
28
|
/**
|
|
35
29
|
* VersionedNonce class representing a versioned expirable nonce
|
|
36
30
|
*
|
|
@@ -62,15 +56,16 @@ const SALTED_NONCE_BORSH_SCHEMA = { struct: {
|
|
|
62
56
|
let VersionedNonceBuilder;
|
|
63
57
|
(function(_VersionedNonceBuilder) {
|
|
64
58
|
function encodeNonce(salt, deadline) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
if (salt.length !== 4) throw new Error(`Invalid salt length: ${salt.length}, expected 4`);
|
|
60
|
+
const deadlineBigInt = BigInt(deadline.getTime()) * 1000000n;
|
|
61
|
+
const nonceBytes = crypto.getRandomValues(new Uint8Array(15));
|
|
62
|
+
const borshBytes = new Uint8Array(27);
|
|
63
|
+
borshBytes.set(salt, 0);
|
|
64
|
+
new DataView(borshBytes.buffer, borshBytes.byteOffset, borshBytes.byteLength).setBigUint64(4, deadlineBigInt, true);
|
|
65
|
+
borshBytes.set(nonceBytes, 12);
|
|
71
66
|
const result = new Uint8Array(5 + borshBytes.length);
|
|
72
67
|
result.set(VERSIONED_MAGIC_PREFIX, 0);
|
|
73
|
-
result.set([
|
|
68
|
+
result.set([LATEST_VERSION], 4);
|
|
74
69
|
result.set(borshBytes, 5);
|
|
75
70
|
return __scure_base.base64.encode(result);
|
|
76
71
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { base64 } from "@scure/base";
|
|
2
2
|
import * as v from "valibot";
|
|
3
|
-
import { deserialize
|
|
3
|
+
import { deserialize } from "near-api-js/lib/utils/serialize";
|
|
4
4
|
|
|
5
5
|
//#region src/intents/expirable-nonce.ts
|
|
6
6
|
const VERSIONED_MAGIC_PREFIX = new Uint8Array([
|
|
@@ -21,12 +21,6 @@ const saltedNonceSchema = v.object({
|
|
|
21
21
|
nonce: v.array(v.number())
|
|
22
22
|
})
|
|
23
23
|
});
|
|
24
|
-
var SaltedNonce = class {
|
|
25
|
-
constructor(salt, inner) {
|
|
26
|
-
this.salt = salt;
|
|
27
|
-
this.inner = inner;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
24
|
/**
|
|
31
25
|
* VersionedNonce class representing a versioned expirable nonce
|
|
32
26
|
*
|
|
@@ -58,15 +52,16 @@ const SALTED_NONCE_BORSH_SCHEMA = { struct: {
|
|
|
58
52
|
let VersionedNonceBuilder;
|
|
59
53
|
(function(_VersionedNonceBuilder) {
|
|
60
54
|
function encodeNonce(salt, deadline) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
if (salt.length !== 4) throw new Error(`Invalid salt length: ${salt.length}, expected 4`);
|
|
56
|
+
const deadlineBigInt = BigInt(deadline.getTime()) * 1000000n;
|
|
57
|
+
const nonceBytes = crypto.getRandomValues(new Uint8Array(15));
|
|
58
|
+
const borshBytes = new Uint8Array(27);
|
|
59
|
+
borshBytes.set(salt, 0);
|
|
60
|
+
new DataView(borshBytes.buffer, borshBytes.byteOffset, borshBytes.byteLength).setBigUint64(4, deadlineBigInt, true);
|
|
61
|
+
borshBytes.set(nonceBytes, 12);
|
|
67
62
|
const result = new Uint8Array(5 + borshBytes.length);
|
|
68
63
|
result.set(VERSIONED_MAGIC_PREFIX, 0);
|
|
69
|
-
result.set([
|
|
64
|
+
result.set([LATEST_VERSION], 4);
|
|
70
65
|
result.set(borshBytes, 5);
|
|
71
66
|
return base64.encode(result);
|
|
72
67
|
}
|