@spicenet-io/spiceflow-core 0.1.1 → 0.1.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.
- package/dist/authorization.d.ts +21 -13
- package/dist/authorization.d.ts.map +1 -1
- package/dist/core.d.ts +1 -6
- package/dist/core.d.ts.map +1 -1
- package/dist/index.cjs +22 -18
- package/dist/index.js +19 -16
- package/dist/types.d.ts +2 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/authorization.d.ts
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import type { Address, Hash, PublicClient } from "viem";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ChainBatch, ChainBatchInput } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* ABI description of a single call in a chain batch.
|
|
5
|
+
*/
|
|
6
|
+
export declare const CallAbi: {
|
|
7
|
+
readonly type: "tuple";
|
|
8
|
+
readonly components: readonly [{
|
|
9
|
+
readonly name: "to";
|
|
10
|
+
readonly type: "address";
|
|
11
|
+
}, {
|
|
12
|
+
readonly name: "value";
|
|
13
|
+
readonly type: "uint";
|
|
14
|
+
}, {
|
|
15
|
+
readonly name: "data";
|
|
16
|
+
readonly type: "bytes";
|
|
17
|
+
}];
|
|
18
|
+
};
|
|
3
19
|
/**
|
|
4
20
|
* ABI description of the per-chain signature components used by EIP‑7702
|
|
5
21
|
* to derive the chain authorization hash for a batch of calls.
|
|
6
22
|
*/
|
|
7
|
-
export declare const
|
|
23
|
+
export declare const ChainBatchHashComponentsAbi: readonly [{
|
|
8
24
|
readonly name: "chainId";
|
|
9
25
|
readonly type: "uint256";
|
|
10
26
|
}, {
|
|
11
|
-
readonly name: "calls";
|
|
12
27
|
readonly type: "tuple[]";
|
|
13
28
|
readonly components: readonly [{
|
|
14
29
|
readonly name: "to";
|
|
@@ -20,23 +35,16 @@ export declare const ChainAuthorizationSignatureComponentsAbi: readonly [{
|
|
|
20
35
|
readonly name: "data";
|
|
21
36
|
readonly type: "bytes";
|
|
22
37
|
}];
|
|
23
|
-
|
|
24
|
-
readonly name: "recentBlock";
|
|
25
|
-
readonly type: "uint256";
|
|
38
|
+
readonly name: "calls";
|
|
26
39
|
}];
|
|
27
40
|
/**
|
|
28
41
|
* Hash each chain's call batch into an EIP‑7702 chain authorization tuple.
|
|
29
42
|
*/
|
|
30
|
-
export declare function hashChainBatches(chainCalls:
|
|
31
|
-
hash: `0x${string}`;
|
|
32
|
-
chainId: bigint;
|
|
33
|
-
calls: Call[];
|
|
34
|
-
recentBlock: bigint;
|
|
35
|
-
}[];
|
|
43
|
+
export declare function hashChainBatches(chainCalls: ChainBatchInput[]): ChainBatch[];
|
|
36
44
|
/**
|
|
37
45
|
* Compute the intent hash from an array of per-chain authorization hashes.
|
|
38
46
|
*/
|
|
39
|
-
export declare function
|
|
47
|
+
export declare function getIntentHash(nbf: bigint, exp: bigint, chainBatches: {
|
|
40
48
|
hash: Hash;
|
|
41
49
|
}[]): Hash;
|
|
42
50
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAExD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAExD,OAAO,KAAK,EAAQ,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;CAOV,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;EAG9B,CAAC;AAEX;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,eAAe,EAAE,GAAG,UAAU,EAAE,CAU5E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,EAAE,GAAG,IAAI,CAG5F;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAEnG;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAEhF"}
|
package/dist/core.d.ts
CHANGED
|
@@ -39,12 +39,7 @@ export declare class SpiceFlowCore {
|
|
|
39
39
|
calls: Call[];
|
|
40
40
|
recentBlock?: bigint;
|
|
41
41
|
}[]): Promise<{
|
|
42
|
-
chainBatches:
|
|
43
|
-
hash: `0x${string}`;
|
|
44
|
-
chainId: bigint;
|
|
45
|
-
calls: Call[];
|
|
46
|
-
recentBlock: bigint;
|
|
47
|
-
}[];
|
|
42
|
+
chainBatches: import("./types.js").ChainBatch[];
|
|
48
43
|
digest: `0x${string}`;
|
|
49
44
|
}>;
|
|
50
45
|
/** Sign the final intent hash (EIP‑7702). */
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAmC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAmC,gBAAgB,EAAiB,MAAM,oBAAoB,CAAC;AACtG,OAAO,KAAK,EAAE,eAAe,EAAE,MAA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MAAM,EAAE,CAAC;IAE/D;;OAEG;IACG,YAAY,CAAC,GAAG,EAAE;QACtB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;QACpB,aAAa,EAAE,aAAa,EAAE,CAAC;QAC/B,YAAY,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;QAClD,YAAY,EAAE,KAAK,MAAM,EAAE,CAAC;QAC5B,WAAW,EAAE,MAAM,CAAC;QACpB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;KAC3B;CAWF"}
|
package/dist/index.cjs
CHANGED
|
@@ -19,10 +19,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/index.ts
|
|
20
20
|
var index_exports = {};
|
|
21
21
|
__export(index_exports, {
|
|
22
|
-
|
|
22
|
+
CallAbi: () => CallAbi,
|
|
23
|
+
ChainBatchHashComponentsAbi: () => ChainBatchHashComponentsAbi,
|
|
23
24
|
SpiceFlowCore: () => SpiceFlowCore,
|
|
24
25
|
getAccountNonce: () => getAccountNonce,
|
|
25
|
-
|
|
26
|
+
getIntentHash: () => getIntentHash,
|
|
26
27
|
getIntentStepStatus: () => getIntentStepStatus,
|
|
27
28
|
getRecentBlock: () => getRecentBlock,
|
|
28
29
|
hashChainBatches: () => hashChainBatches,
|
|
@@ -33,27 +34,29 @@ module.exports = __toCommonJS(index_exports);
|
|
|
33
34
|
|
|
34
35
|
// src/authorization.ts
|
|
35
36
|
var import_viem = require("viem");
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
var CallAbi = {
|
|
38
|
+
type: "tuple",
|
|
39
|
+
components: [
|
|
39
40
|
{ name: "to", type: "address" },
|
|
40
41
|
{ name: "value", type: "uint" },
|
|
41
42
|
{ name: "data", type: "bytes" }
|
|
42
|
-
]
|
|
43
|
-
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
var ChainBatchHashComponentsAbi = [
|
|
46
|
+
{ name: "chainId", type: "uint256" },
|
|
47
|
+
{ name: "calls", ...CallAbi, type: "tuple[]" }
|
|
44
48
|
];
|
|
45
49
|
function hashChainBatches(chainCalls) {
|
|
46
|
-
return chainCalls.map(({ chainId, calls
|
|
47
|
-
|
|
48
|
-
const rb = BigInt(recentBlock);
|
|
50
|
+
return chainCalls.map(({ chainId, calls }) => {
|
|
51
|
+
chainId = BigInt(chainId);
|
|
49
52
|
const hash = (0, import_viem.keccak256)(
|
|
50
|
-
(0, import_viem.encodeAbiParameters)(
|
|
53
|
+
(0, import_viem.encodeAbiParameters)(ChainBatchHashComponentsAbi, [chainId, calls])
|
|
51
54
|
);
|
|
52
|
-
return { hash, chainId
|
|
55
|
+
return { hash, chainId, calls };
|
|
53
56
|
});
|
|
54
57
|
}
|
|
55
|
-
function
|
|
56
|
-
const hashes =
|
|
58
|
+
function getIntentHash(nbf, exp, chainBatches) {
|
|
59
|
+
const hashes = chainBatches.map(({ hash }) => hash);
|
|
57
60
|
return (0, import_viem.keccak256)((0, import_viem.encodeAbiParameters)([{ type: "uint256" }, { type: "uint256" }, { type: "bytes32[]" }], [nbf, exp, hashes]));
|
|
58
61
|
}
|
|
59
62
|
async function getAccountNonce(address, publicClient) {
|
|
@@ -170,7 +173,7 @@ var SpiceFlowCore = class {
|
|
|
170
173
|
filled.push({ chainId: c.chainId, calls: c.calls, recentBlock: recent });
|
|
171
174
|
}
|
|
172
175
|
const chainBatches = hashChainBatches(filled);
|
|
173
|
-
const digest =
|
|
176
|
+
const digest = getIntentHash(nbf, exp, chainBatches);
|
|
174
177
|
return { chainBatches, digest };
|
|
175
178
|
}
|
|
176
179
|
/** Sign the final intent hash (EIP‑7702). */
|
|
@@ -181,7 +184,7 @@ var SpiceFlowCore = class {
|
|
|
181
184
|
* Submit a signed intent to the SpiceFlow relayer.
|
|
182
185
|
*/
|
|
183
186
|
async submitIntent(req) {
|
|
184
|
-
const signature = req.signature ?? await this.signIntent(
|
|
187
|
+
const signature = req.signature ?? await this.signIntent(getIntentHash(req.nbf, req.exp, req.chainBatches));
|
|
185
188
|
const resp = await submitTransaction(this.cfg.txApiUrl, {
|
|
186
189
|
tokenAddress: req.tokenAddress,
|
|
187
190
|
tokenAmount: req.tokenAmount,
|
|
@@ -210,10 +213,11 @@ async function prepareRFQT(txApiUrl, request, retry) {
|
|
|
210
213
|
}
|
|
211
214
|
// Annotate the CommonJS export names for ESM import in node:
|
|
212
215
|
0 && (module.exports = {
|
|
213
|
-
|
|
216
|
+
CallAbi,
|
|
217
|
+
ChainBatchHashComponentsAbi,
|
|
214
218
|
SpiceFlowCore,
|
|
215
219
|
getAccountNonce,
|
|
216
|
-
|
|
220
|
+
getIntentHash,
|
|
217
221
|
getIntentStepStatus,
|
|
218
222
|
getRecentBlock,
|
|
219
223
|
hashChainBatches,
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
// src/authorization.ts
|
|
2
2
|
import { encodeAbiParameters, keccak256 } from "viem";
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
var CallAbi = {
|
|
4
|
+
type: "tuple",
|
|
5
|
+
components: [
|
|
6
6
|
{ name: "to", type: "address" },
|
|
7
7
|
{ name: "value", type: "uint" },
|
|
8
8
|
{ name: "data", type: "bytes" }
|
|
9
|
-
]
|
|
10
|
-
|
|
9
|
+
]
|
|
10
|
+
};
|
|
11
|
+
var ChainBatchHashComponentsAbi = [
|
|
12
|
+
{ name: "chainId", type: "uint256" },
|
|
13
|
+
{ name: "calls", ...CallAbi, type: "tuple[]" }
|
|
11
14
|
];
|
|
12
15
|
function hashChainBatches(chainCalls) {
|
|
13
|
-
return chainCalls.map(({ chainId, calls
|
|
14
|
-
|
|
15
|
-
const rb = BigInt(recentBlock);
|
|
16
|
+
return chainCalls.map(({ chainId, calls }) => {
|
|
17
|
+
chainId = BigInt(chainId);
|
|
16
18
|
const hash = keccak256(
|
|
17
|
-
encodeAbiParameters(
|
|
19
|
+
encodeAbiParameters(ChainBatchHashComponentsAbi, [chainId, calls])
|
|
18
20
|
);
|
|
19
|
-
return { hash, chainId
|
|
21
|
+
return { hash, chainId, calls };
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
|
-
function
|
|
23
|
-
const hashes =
|
|
24
|
+
function getIntentHash(nbf, exp, chainBatches) {
|
|
25
|
+
const hashes = chainBatches.map(({ hash }) => hash);
|
|
24
26
|
return keccak256(encodeAbiParameters([{ type: "uint256" }, { type: "uint256" }, { type: "bytes32[]" }], [nbf, exp, hashes]));
|
|
25
27
|
}
|
|
26
28
|
async function getAccountNonce(address, publicClient) {
|
|
@@ -137,7 +139,7 @@ var SpiceFlowCore = class {
|
|
|
137
139
|
filled.push({ chainId: c.chainId, calls: c.calls, recentBlock: recent });
|
|
138
140
|
}
|
|
139
141
|
const chainBatches = hashChainBatches(filled);
|
|
140
|
-
const digest =
|
|
142
|
+
const digest = getIntentHash(nbf, exp, chainBatches);
|
|
141
143
|
return { chainBatches, digest };
|
|
142
144
|
}
|
|
143
145
|
/** Sign the final intent hash (EIP‑7702). */
|
|
@@ -148,7 +150,7 @@ var SpiceFlowCore = class {
|
|
|
148
150
|
* Submit a signed intent to the SpiceFlow relayer.
|
|
149
151
|
*/
|
|
150
152
|
async submitIntent(req) {
|
|
151
|
-
const signature = req.signature ?? await this.signIntent(
|
|
153
|
+
const signature = req.signature ?? await this.signIntent(getIntentHash(req.nbf, req.exp, req.chainBatches));
|
|
152
154
|
const resp = await submitTransaction(this.cfg.txApiUrl, {
|
|
153
155
|
tokenAddress: req.tokenAddress,
|
|
154
156
|
tokenAmount: req.tokenAmount,
|
|
@@ -176,10 +178,11 @@ async function prepareRFQT(txApiUrl, request, retry) {
|
|
|
176
178
|
return res.json();
|
|
177
179
|
}
|
|
178
180
|
export {
|
|
179
|
-
|
|
181
|
+
CallAbi,
|
|
182
|
+
ChainBatchHashComponentsAbi,
|
|
180
183
|
SpiceFlowCore,
|
|
181
184
|
getAccountNonce,
|
|
182
|
-
|
|
185
|
+
getIntentHash,
|
|
183
186
|
getIntentStepStatus,
|
|
184
187
|
getRecentBlock,
|
|
185
188
|
hashChainBatches,
|
package/dist/types.d.ts
CHANGED
|
@@ -15,16 +15,14 @@ export type Authorization = {
|
|
|
15
15
|
yParity: number;
|
|
16
16
|
};
|
|
17
17
|
/** Input for hashing a per-chain authorization (preimage). */
|
|
18
|
-
export type
|
|
18
|
+
export type ChainBatchInput = {
|
|
19
19
|
chainId: bigint | number;
|
|
20
20
|
calls: Call[];
|
|
21
|
-
recentBlock: bigint | number;
|
|
22
21
|
};
|
|
23
22
|
/** Output of hashing: the EIP‑7702 chain authorization tuple. */
|
|
24
|
-
export type
|
|
23
|
+
export type ChainBatch = {
|
|
25
24
|
hash: Hash;
|
|
26
25
|
chainId: bigint;
|
|
27
26
|
calls: Call[];
|
|
28
|
-
recentBlock: bigint;
|
|
29
27
|
};
|
|
30
28
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAE/C,+CAA+C;AAC/C,MAAM,MAAM,IAAI,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAAC;AAC7D,gFAAgF;AAChF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,8DA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