n3-sdk 0.2.5 → 0.2.7
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/exchange/depositERC20.d.ts +15 -3
- package/dist/exchange/depositERC20.d.ts.map +1 -1
- package/dist/exchange/depositERC20.js +36 -26
- package/dist/exchange/depositHYPE.d.ts +5 -3
- package/dist/exchange/depositHYPE.d.ts.map +1 -1
- package/dist/exchange/depositHYPE.js +18 -18
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/lib/utils/formattingHelpers.d.ts +1 -1
- package/dist/lib/utils/formattingHelpers.d.ts.map +1 -1
- package/dist/lib/utils/formattingHelpers.js +10 -8
- package/dist/lib/utils/rand.d.ts +4 -0
- package/dist/lib/utils/rand.d.ts.map +1 -0
- package/dist/lib/utils/rand.js +19 -0
- package/dist/lib/utils/redis.d.ts +1 -1
- package/dist/lib/utils/redis.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import type { N3Clients } from
|
|
2
|
-
import type { NoteStore } from
|
|
3
|
-
import type { NoteV1 } from
|
|
1
|
+
import type { N3Clients } from "../lib/client.js";
|
|
2
|
+
import type { NoteStore } from "../notes/store.js";
|
|
3
|
+
import type { NoteV1 } from "../types/NoteStoreTypes.js";
|
|
4
|
+
export type DepositPokePayload = {
|
|
5
|
+
pool: `0x${string}`;
|
|
6
|
+
chainId: number;
|
|
7
|
+
tx: `0x${string}`;
|
|
8
|
+
assetId: string;
|
|
9
|
+
amount: string;
|
|
10
|
+
commitment: `0x${string}`;
|
|
11
|
+
notePubkey?: string;
|
|
12
|
+
user?: `0x${string}`;
|
|
13
|
+
ts?: number;
|
|
14
|
+
};
|
|
4
15
|
export declare function depositERC20({ clients, pool, chainId, token, assetId, amount, seed, sysAddress, store, }: {
|
|
5
16
|
clients: N3Clients;
|
|
6
17
|
pool: `0x${string}`;
|
|
@@ -15,5 +26,6 @@ export declare function depositERC20({ clients, pool, chainId, token, assetId, a
|
|
|
15
26
|
hash: `0x${string}`;
|
|
16
27
|
receipt: import("viem").TransactionReceipt;
|
|
17
28
|
note: NoteV1;
|
|
29
|
+
poke: DepositPokePayload;
|
|
18
30
|
}>;
|
|
19
31
|
//# sourceMappingURL=depositERC20.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"depositERC20.d.ts","sourceRoot":"","sources":["../../src/exchange/depositERC20.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"depositERC20.d.ts","sourceRoot":"","sources":["../../src/exchange/depositERC20.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,KAAK,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,KAAK,MAAM,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAOF,wBAAsB,YAAY,CAAC,EACjC,OAAO,EACP,IAAI,EACJ,OAAO,EACP,KAAK,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,UAAU,EACV,KAAK,GACN,EAAE;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;;;;;GA2EA"}
|
|
@@ -1,64 +1,74 @@
|
|
|
1
|
-
import { erc20Abi } from
|
|
2
|
-
import { initPoseidon, genNote, makeDepositCommitments } from
|
|
3
|
-
import { PrivatePoolAbi as POOL_ABI } from
|
|
4
|
-
import { publishDepositPoke } from '../lib/utils/redis.js';
|
|
1
|
+
import { erc20Abi } from "viem";
|
|
2
|
+
import { initPoseidon, genNote, makeDepositCommitments } from "../lib/utils/poseidon.js";
|
|
3
|
+
import { PrivatePoolAbi as POOL_ABI } from "../lib/consts/poolAbi.js";
|
|
5
4
|
function sysAddressFromAssetId(assetId) {
|
|
6
5
|
const val = (0x20n << 152n) | assetId;
|
|
7
|
-
return (`0x${val.toString(16).padStart(40,
|
|
6
|
+
return (`0x${val.toString(16).padStart(40, "0")}`);
|
|
8
7
|
}
|
|
9
8
|
export async function depositERC20({ clients, pool, chainId, token, assetId, amount, seed, sysAddress, store, }) {
|
|
10
9
|
await initPoseidon();
|
|
11
|
-
const {
|
|
10
|
+
const { skBytes, Ax, Ay, pubkey, blinding } = await genNote(seed);
|
|
12
11
|
const { commitment } = makeDepositCommitments(assetId, amount, pubkey, blinding);
|
|
13
12
|
const sys = sysAddress ?? sysAddressFromAssetId(assetId);
|
|
14
13
|
const { publicClient, walletClient, account } = clients;
|
|
15
|
-
const allowance = await publicClient.readContract({
|
|
16
|
-
address: token,
|
|
14
|
+
const allowance = (await publicClient.readContract({
|
|
15
|
+
address: token,
|
|
16
|
+
abi: erc20Abi,
|
|
17
|
+
functionName: "allowance",
|
|
17
18
|
args: [account.address, pool],
|
|
18
|
-
});
|
|
19
|
+
}));
|
|
19
20
|
if (allowance < amount) {
|
|
20
21
|
const { request } = await publicClient.simulateContract({
|
|
21
|
-
address: token,
|
|
22
|
-
|
|
22
|
+
address: token,
|
|
23
|
+
abi: erc20Abi,
|
|
24
|
+
functionName: "approve",
|
|
25
|
+
args: [pool, amount],
|
|
26
|
+
account,
|
|
23
27
|
});
|
|
24
28
|
const h = await walletClient.writeContract(request);
|
|
25
29
|
await publicClient.waitForTransactionReceipt({ hash: h });
|
|
26
30
|
}
|
|
27
31
|
const { request } = await publicClient.simulateContract({
|
|
28
|
-
address: pool,
|
|
29
|
-
|
|
32
|
+
address: pool,
|
|
33
|
+
abi: POOL_ABI,
|
|
34
|
+
functionName: "depositERC20",
|
|
35
|
+
args: [assetId, amount, commitment, token, sys],
|
|
36
|
+
account,
|
|
30
37
|
});
|
|
31
38
|
const hash = await walletClient.writeContract(request);
|
|
32
39
|
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
33
40
|
const note = {
|
|
34
41
|
version: 1,
|
|
35
|
-
commitment: `0x${BigInt(commitment).toString(16).padStart(64,
|
|
36
|
-
chainId,
|
|
37
|
-
|
|
42
|
+
commitment: `0x${BigInt(commitment).toString(16).padStart(64, "0")}`,
|
|
43
|
+
chainId,
|
|
44
|
+
pool,
|
|
45
|
+
assetId,
|
|
46
|
+
amount,
|
|
38
47
|
ownerPub: { x: BigInt(Ax), y: BigInt(Ay) },
|
|
39
48
|
notePubkey: BigInt(pubkey),
|
|
40
49
|
secret: {
|
|
41
50
|
sk: skBytes,
|
|
42
51
|
blind: (() => {
|
|
43
|
-
const hex = BigInt(blinding).toString(16).padStart(64,
|
|
44
|
-
return Uint8Array.from(Buffer.from(hex,
|
|
45
|
-
})()
|
|
52
|
+
const hex = BigInt(blinding).toString(16).padStart(64, "0");
|
|
53
|
+
return Uint8Array.from(Buffer.from(hex, "hex"));
|
|
54
|
+
})(),
|
|
46
55
|
},
|
|
47
|
-
status:
|
|
56
|
+
status: "STAGED",
|
|
48
57
|
createdAt: Date.now(),
|
|
49
58
|
updatedAt: Date.now(),
|
|
50
59
|
};
|
|
51
60
|
if (store)
|
|
52
61
|
await store.addStagedNotes([note]);
|
|
53
|
-
|
|
62
|
+
const poke = {
|
|
54
63
|
pool,
|
|
55
64
|
chainId,
|
|
56
65
|
tx: hash,
|
|
57
|
-
assetId,
|
|
58
|
-
amount,
|
|
66
|
+
assetId: assetId.toString(),
|
|
67
|
+
amount: amount.toString(),
|
|
59
68
|
commitment: note.commitment,
|
|
60
|
-
notePubkey: note.notePubkey,
|
|
69
|
+
notePubkey: note.notePubkey?.toString(),
|
|
61
70
|
user: account.address,
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
ts: Date.now(),
|
|
72
|
+
};
|
|
73
|
+
return { hash, receipt, note, poke };
|
|
64
74
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { N3Clients } from
|
|
2
|
-
import type { NoteStore } from
|
|
3
|
-
import type { NoteV1 } from
|
|
1
|
+
import type { N3Clients } from "../lib/client.js";
|
|
2
|
+
import type { NoteStore } from "../notes/store.js";
|
|
3
|
+
import type { NoteV1 } from "../types/NoteStoreTypes.js";
|
|
4
|
+
import type { DepositPokePayload } from "./depositERC20.js";
|
|
4
5
|
export declare function depositHYPE({ clients, pool, chainId, amountWei, seed, store, }: {
|
|
5
6
|
clients: N3Clients;
|
|
6
7
|
pool: `0x${string}`;
|
|
@@ -12,5 +13,6 @@ export declare function depositHYPE({ clients, pool, chainId, amountWei, seed, s
|
|
|
12
13
|
hash: `0x${string}`;
|
|
13
14
|
receipt: import("viem").TransactionReceipt;
|
|
14
15
|
note: NoteV1;
|
|
16
|
+
poke: DepositPokePayload;
|
|
15
17
|
}>;
|
|
16
18
|
//# sourceMappingURL=depositHYPE.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"depositHYPE.d.ts","sourceRoot":"","sources":["../../src/exchange/depositHYPE.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"depositHYPE.d.ts","sourceRoot":"","sources":["../../src/exchange/depositHYPE.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAI5D,wBAAsB,WAAW,CAAC,EAChC,OAAO,EACP,IAAI,EACJ,OAAO,EACP,SAAS,EACT,IAAI,EACJ,KAAK,GACN,EAAE;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;;;;;GAwDA"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { initPoseidon, genNote, makeDepositCommitments } from
|
|
2
|
-
import { PrivatePoolAbi as POOL_ABI } from
|
|
3
|
-
import { publishDepositPoke } from '../lib/utils/redis.js';
|
|
1
|
+
import { initPoseidon, genNote, makeDepositCommitments } from "../lib/utils/poseidon.js";
|
|
2
|
+
import { PrivatePoolAbi as POOL_ABI } from "../lib/consts/poolAbi.js";
|
|
4
3
|
const HYPE_ASSET_ID = 150n;
|
|
5
4
|
export async function depositHYPE({ clients, pool, chainId, amountWei, seed, store, }) {
|
|
6
5
|
await initPoseidon();
|
|
7
|
-
const {
|
|
6
|
+
const { skBytes, Ax, Ay, pubkey, blinding } = await genNote(seed);
|
|
8
7
|
const { commitment } = makeDepositCommitments(HYPE_ASSET_ID, amountWei, pubkey, blinding);
|
|
9
8
|
const { publicClient, walletClient, account } = clients;
|
|
10
9
|
const { request } = await publicClient.simulateContract({
|
|
11
10
|
address: pool,
|
|
12
11
|
abi: POOL_ABI,
|
|
13
|
-
functionName:
|
|
12
|
+
functionName: "depositHYPE",
|
|
14
13
|
args: [commitment],
|
|
15
14
|
value: amountWei,
|
|
16
15
|
account,
|
|
@@ -19,8 +18,9 @@ export async function depositHYPE({ clients, pool, chainId, amountWei, seed, sto
|
|
|
19
18
|
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
20
19
|
const note = {
|
|
21
20
|
version: 1,
|
|
22
|
-
commitment: `0x${BigInt(commitment).toString(16).padStart(64,
|
|
23
|
-
chainId,
|
|
21
|
+
commitment: `0x${BigInt(commitment).toString(16).padStart(64, "0")}`,
|
|
22
|
+
chainId,
|
|
23
|
+
pool,
|
|
24
24
|
assetId: HYPE_ASSET_ID,
|
|
25
25
|
amount: amountWei,
|
|
26
26
|
ownerPub: { x: BigInt(Ax), y: BigInt(Ay) },
|
|
@@ -28,26 +28,26 @@ export async function depositHYPE({ clients, pool, chainId, amountWei, seed, sto
|
|
|
28
28
|
secret: {
|
|
29
29
|
sk: skBytes,
|
|
30
30
|
blind: (() => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})()
|
|
31
|
+
const hex = BigInt(blinding).toString(16).padStart(64, "0");
|
|
32
|
+
return Uint8Array.from(Buffer.from(hex, "hex"));
|
|
33
|
+
})(),
|
|
35
34
|
},
|
|
36
|
-
status:
|
|
35
|
+
status: "STAGED",
|
|
37
36
|
createdAt: Date.now(),
|
|
38
37
|
updatedAt: Date.now(),
|
|
39
38
|
};
|
|
40
39
|
if (store)
|
|
41
40
|
await store.addStagedNotes([note]);
|
|
42
|
-
|
|
41
|
+
const poke = {
|
|
43
42
|
pool,
|
|
44
43
|
chainId,
|
|
45
44
|
tx: hash,
|
|
46
|
-
assetId: HYPE_ASSET_ID,
|
|
47
|
-
amount: amountWei,
|
|
45
|
+
assetId: HYPE_ASSET_ID.toString(),
|
|
46
|
+
amount: amountWei.toString(),
|
|
48
47
|
commitment: note.commitment,
|
|
49
|
-
notePubkey: note.notePubkey,
|
|
48
|
+
notePubkey: note.notePubkey?.toString(),
|
|
50
49
|
user: account.address,
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
ts: Date.now(),
|
|
51
|
+
};
|
|
52
|
+
return { hash, receipt, note, poke };
|
|
53
53
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type { N3Env } from './data/config.js';
|
|
2
2
|
export { Topics, type TopicName, type AssetId } from './data/_common.js';
|
|
3
|
+
export { publishDepositPoke, publishIntent, publishEncryptedIntent, redis } from "./lib/utils/redis.js";
|
|
4
|
+
export type { DepositPoke } from "./lib/utils/redis.js";
|
|
3
5
|
export * as Info from './info/index.js';
|
|
4
6
|
export * as Subscription from './subscription/index.js';
|
|
5
7
|
export * as Exchange from './exchange/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,E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iB,IAAI,SAAS;IAO9B;;;;;OAKG;IACH,iBAAiB,CACf,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,SAAS,EACnB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;CAmF9B;AAED,eAAe,KAAK,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
export { Topics } from './data/_common.js';
|
|
3
|
+
export { publishDepositPoke, publishIntent, publishEncryptedIntent, redis } from "./lib/utils/redis.js";
|
|
3
4
|
// Namespaced re-exports (tree-shakable)
|
|
4
5
|
export * as Info from './info/index.js';
|
|
5
6
|
export * as Subscription from './subscription/index.js';
|
|
@@ -5,7 +5,7 @@ export declare const toHex32Lower: (x: string | bigint) => `0x${string}`;
|
|
|
5
5
|
export declare function toU8(objOrHexOrU8: any): Uint8Array;
|
|
6
6
|
export declare const u8ToHex: (u8: Uint8Array) => `0x${string}`;
|
|
7
7
|
export declare const u8ToBigIntBE: (u8: Uint8Array) => bigint;
|
|
8
|
-
export declare
|
|
8
|
+
export declare function randU256(): Promise<bigint>;
|
|
9
9
|
export declare function skToHex32(sk: any): string | undefined;
|
|
10
10
|
export declare function derivePrvSeedFromNote(note: any): string | undefined;
|
|
11
11
|
export declare function deriveAxAyFromNote(note: any): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formattingHelpers.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/formattingHelpers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,EAAE,GAAI,GAAG,GAAG,WAA4C,CAAC;AACtE,eAAO,MAAM,OAAO,QAAoB,CAAC;AACzC,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,WAAgC,CAAC;AAC7E,eAAO,MAAM,YAAY,GAAI,GAAG,MAAM,GAAG,MAAM,KAEQ,KAAK,MAAM,EACjE,CAAC;AAEF,wBAAgB,IAAI,CAAC,YAAY,EAAE,GAAG,GAAG,UAAU,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
-
import
|
|
1
|
+
import { randU256 as _randU256 } from "./rand.js";
|
|
2
2
|
// ========= helpers =========
|
|
3
3
|
export const BI = (x) => (typeof x === 'bigint' ? x : BigInt(x));
|
|
4
4
|
export const mask160 = (1n << 160n) - 1n;
|
|
@@ -10,27 +10,29 @@ export const toHex32Lower = (x) => {
|
|
|
10
10
|
export function toU8(objOrHexOrU8) {
|
|
11
11
|
if (objOrHexOrU8 instanceof Uint8Array)
|
|
12
12
|
return objOrHexOrU8;
|
|
13
|
-
if (typeof objOrHexOrU8 ===
|
|
14
|
-
const hex = objOrHexOrU8.startsWith(
|
|
13
|
+
if (typeof objOrHexOrU8 === "string") {
|
|
14
|
+
const hex = objOrHexOrU8.startsWith("0x") ? objOrHexOrU8.slice(2) : objOrHexOrU8;
|
|
15
15
|
if (hex.length % 2)
|
|
16
|
-
throw new Error(
|
|
16
|
+
throw new Error("hex string must have even length");
|
|
17
17
|
const out = new Uint8Array(hex.length / 2);
|
|
18
18
|
for (let i = 0; i < out.length; i++)
|
|
19
19
|
out[i] = parseInt(hex.slice(2 * i, 2 * i + 2), 16);
|
|
20
20
|
return out;
|
|
21
21
|
}
|
|
22
|
-
if (objOrHexOrU8 && typeof objOrHexOrU8 ===
|
|
22
|
+
if (objOrHexOrU8 && typeof objOrHexOrU8 === "object") {
|
|
23
23
|
const keys = Object.keys(objOrHexOrU8).map(Number).sort((a, b) => a - b);
|
|
24
24
|
const out = new Uint8Array(keys.length);
|
|
25
25
|
for (let i = 0; i < keys.length; i++)
|
|
26
26
|
out[i] = Number(objOrHexOrU8[keys[i]]);
|
|
27
27
|
return out;
|
|
28
28
|
}
|
|
29
|
-
throw new Error(
|
|
29
|
+
throw new Error("toU8: unsupported input");
|
|
30
30
|
}
|
|
31
|
-
export const u8ToHex = (u8) => (
|
|
31
|
+
export const u8ToHex = (u8) => ("0x" + [...u8].map((b) => b.toString(16).padStart(2, "0")).join(""));
|
|
32
32
|
export const u8ToBigIntBE = (u8) => BigInt(u8ToHex(u8));
|
|
33
|
-
export
|
|
33
|
+
export async function randU256() {
|
|
34
|
+
return _randU256();
|
|
35
|
+
}
|
|
34
36
|
export function skToHex32(sk) {
|
|
35
37
|
if (!sk)
|
|
36
38
|
return undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rand.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/rand.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,YAEtB;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC,CASzD;AAED,wBAAsB,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,CAKhD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function isBrowser() {
|
|
2
|
+
return typeof window !== "undefined" && typeof window.crypto !== "undefined";
|
|
3
|
+
}
|
|
4
|
+
export async function randomBytes32() {
|
|
5
|
+
if (isBrowser()) {
|
|
6
|
+
const u8 = new Uint8Array(32);
|
|
7
|
+
window.crypto.getRandomValues(u8);
|
|
8
|
+
return u8;
|
|
9
|
+
}
|
|
10
|
+
const mod = await import("node:crypto");
|
|
11
|
+
return mod.randomBytes(32);
|
|
12
|
+
}
|
|
13
|
+
export async function randU256() {
|
|
14
|
+
const b = await randomBytes32();
|
|
15
|
+
let hex = "0x";
|
|
16
|
+
for (let i = 0; i < b.length; i++)
|
|
17
|
+
hex += b[i].toString(16).padStart(2, "0");
|
|
18
|
+
return BigInt(hex);
|
|
19
|
+
}
|
|
@@ -14,7 +14,7 @@ export declare function publishEncryptedIntent(redisClient: Redis, { intent, att
|
|
|
14
14
|
* All callers should keep using publishIntent; it just routes to encrypted.
|
|
15
15
|
*/
|
|
16
16
|
export declare function publishIntent(intent: any): Promise<string | null>;
|
|
17
|
-
type DepositPoke = {
|
|
17
|
+
export type DepositPoke = {
|
|
18
18
|
pool: `0x${string}`;
|
|
19
19
|
chainId: number;
|
|
20
20
|
tx: `0x${string}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/redis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAK5B,eAAO,MAAM,KAAK,OAIhB,CAAC;AAEH,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAGF,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,KAAK,EAClB,EACE,MAAM,EACN,SAAS,EACT,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,iBAAiB,GAClB,EAAE,oBAAoB,0BAaxB;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,GAAG,0BAa9C;AAED,
|
|
1
|
+
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/redis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAK5B,eAAO,MAAM,KAAK,OAIhB,CAAC;AAEH,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAGF,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,KAAK,EAClB,EACE,MAAM,EACN,SAAS,EACT,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,iBAAiB,GAClB,EAAE,oBAAoB,0BAaxB;AAED;;;GAGG;AACH,wB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