@skalenetwork/privacy-sdk 0.1.0-develop.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/index.js ADDED
@@ -0,0 +1,171 @@
1
+ import {
2
+ approve,
3
+ authorizeHistoricViewForRange,
4
+ authorizeHistoricViewForTransfer,
5
+ confidentialWrapperAbi,
6
+ decryptHistoricTransferData,
7
+ decryptTokenBalance,
8
+ registerViewerKey,
9
+ requestTransferDecryption,
10
+ revokeHistoricView,
11
+ transfer,
12
+ unwrap,
13
+ wrap
14
+ } from "./chunk-YEII26VS.js";
15
+ import {
16
+ createCtxPromise,
17
+ waitForCtx
18
+ } from "./chunk-Y6NM73JA.js";
19
+ import "./chunk-K5WS3F4Q.js";
20
+
21
+ // src/ConfidentialToken.ts
22
+ import { createPublicClient, http, parseEventLogs } from "viem";
23
+ import { BITE } from "@skalenetwork/bite";
24
+ var ConfidentialToken = class {
25
+ rpcUrl;
26
+ address;
27
+ signer;
28
+ viewerPrivateKey;
29
+ client;
30
+ bite;
31
+ constructor(config) {
32
+ this.rpcUrl = config.rpcUrl;
33
+ this.address = config.address;
34
+ this.signer = config.signer;
35
+ this.viewerPrivateKey = config.viewerPrivateKey;
36
+ this.client = createPublicClient({ transport: http(config.rpcUrl) });
37
+ this.bite = new BITE(config.rpcUrl);
38
+ }
39
+ get actionConfig() {
40
+ return {
41
+ rpcUrl: this.rpcUrl,
42
+ address: this.address,
43
+ publicClient: this.client,
44
+ signer: this.signer,
45
+ bite: this.bite
46
+ };
47
+ }
48
+ setViewerPrivateKey(privateKey) {
49
+ this.viewerPrivateKey = privateKey;
50
+ }
51
+ // --- Standard ERC-20 reads ---
52
+ async name() {
53
+ return await this.client.readContract({
54
+ address: this.address,
55
+ abi: confidentialWrapperAbi,
56
+ functionName: "name"
57
+ });
58
+ }
59
+ async symbol() {
60
+ return await this.client.readContract({
61
+ address: this.address,
62
+ abi: confidentialWrapperAbi,
63
+ functionName: "symbol"
64
+ });
65
+ }
66
+ async decimals() {
67
+ return Number(
68
+ await this.client.readContract({
69
+ address: this.address,
70
+ abi: confidentialWrapperAbi,
71
+ functionName: "decimals"
72
+ })
73
+ );
74
+ }
75
+ async allowance(owner, spender) {
76
+ return await this.client.readContract({
77
+ address: this.address,
78
+ abi: confidentialWrapperAbi,
79
+ functionName: "allowance",
80
+ args: [owner, spender]
81
+ });
82
+ }
83
+ // --- Privacy-specific reads ---
84
+ async viewerAddress() {
85
+ return await this.client.readContract({
86
+ address: this.address,
87
+ abi: confidentialWrapperAbi,
88
+ functionName: "viewerAddresses",
89
+ args: [this.signer.address]
90
+ });
91
+ }
92
+ async decryptBalance() {
93
+ if (!this.viewerPrivateKey) {
94
+ throw new Error("Viewer key is required to decrypt balance.");
95
+ }
96
+ return decryptTokenBalance(this.actionConfig, { viewerKey: this.viewerPrivateKey });
97
+ }
98
+ // --- Standard ERC-20 writes ---
99
+ async approve(spender, amount) {
100
+ return approve(this.actionConfig, { spender, amount });
101
+ }
102
+ // --- Privacy-specific writes ---
103
+ transfer(to, amount) {
104
+ return createCtxPromise(
105
+ transfer(this.actionConfig, { to, amount }),
106
+ this.client
107
+ );
108
+ }
109
+ // --- Viewer key management ---
110
+ async registerViewerPublicKey(publicKey) {
111
+ return registerViewerKey(this.actionConfig, { publicKey });
112
+ }
113
+ async authorizeHistoricViewForRange(address, fromTimestamp, toTimestamp) {
114
+ return authorizeHistoricViewForRange(this.actionConfig, {
115
+ address,
116
+ fromTimestamp,
117
+ toTimestamp
118
+ });
119
+ }
120
+ async authorizeHistoricViewForTransfer(address, transferId) {
121
+ return authorizeHistoricViewForTransfer(this.actionConfig, { address, transferId });
122
+ }
123
+ async revokeHistoricView(address) {
124
+ return revokeHistoricView(this.actionConfig, { address });
125
+ }
126
+ // --- Decrypt / history ---
127
+ async requestTransferDecryption(ctxHash) {
128
+ if (!this.viewerPrivateKey) {
129
+ throw new Error("Viewer key is required to decrypt transfer data.");
130
+ }
131
+ const txHash = await requestTransferDecryption(this.actionConfig, { ctxHash });
132
+ const { ctxReceipt } = await waitForCtx(txHash, this.client);
133
+ const events = parseEventLogs({
134
+ abi: confidentialWrapperAbi,
135
+ logs: ctxReceipt.logs,
136
+ eventName: "ReEncryptedTransfer"
137
+ });
138
+ const event = events[0];
139
+ if (!event) {
140
+ throw new Error("CTX receipt does not contain a ReEncryptedTransfer event.");
141
+ }
142
+ const encryptedData = event.args.encryptedTransfer;
143
+ if (!encryptedData) {
144
+ throw new Error("CTX receipt does not contain a ReEncryptedTransfer event.");
145
+ }
146
+ return decryptHistoricTransferData({ encryptedData, viewerKey: this.viewerPrivateKey });
147
+ }
148
+ };
149
+
150
+ // src/ConfidentialWrapper.ts
151
+ var ConfidentialWrapper = class extends ConfidentialToken {
152
+ async underlying() {
153
+ return await this.client.readContract({
154
+ address: this.address,
155
+ abi: confidentialWrapperAbi,
156
+ functionName: "underlying"
157
+ });
158
+ }
159
+ wrap(receiver, amount) {
160
+ return createCtxPromise(wrap(this.actionConfig, { receiver, amount }), this.client);
161
+ }
162
+ unwrap(receiver, amount) {
163
+ return createCtxPromise(unwrap(this.actionConfig, { receiver, amount }), this.client);
164
+ }
165
+ };
166
+ export {
167
+ ConfidentialToken,
168
+ ConfidentialWrapper,
169
+ confidentialWrapperAbi
170
+ };
171
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ConfidentialToken.ts","../src/ConfidentialWrapper.ts"],"sourcesContent":["import { createPublicClient, http, parseEventLogs, type Hex, type PublicClient } from \"viem\";\nimport { BITE } from \"@skalenetwork/bite\";\n\nimport type { ConfidentialTokenConfig, TransferData } from \"./types.js\";\nimport type { ActionConfig } from \"./actions/types.js\";\nimport * as actions from \"./actions/index.js\";\nimport { confidentialWrapperAbi } from \"./abi/confidentialWrapper.js\";\nimport { createCtxPromise, type CtxPromise, waitForCtx } from \"./utils/ctx.js\";\n\nexport class ConfidentialToken {\n readonly rpcUrl: string;\n readonly address: Hex;\n readonly signer: {\n address: Hex;\n sendTransaction(tx: { to: Hex; data: Hex; value?: bigint }): Promise<Hex>;\n };\n private viewerPrivateKey?: Hex;\n protected client: PublicClient;\n private bite: BITE;\n\n constructor(config: ConfidentialTokenConfig) {\n this.rpcUrl = config.rpcUrl;\n this.address = config.address;\n this.signer = config.signer;\n this.viewerPrivateKey = config.viewerPrivateKey;\n this.client = createPublicClient({ transport: http(config.rpcUrl) }) as PublicClient;\n this.bite = new BITE(config.rpcUrl);\n }\n\n protected get actionConfig(): ActionConfig {\n return {\n rpcUrl: this.rpcUrl,\n address: this.address,\n publicClient: this.client,\n signer: this.signer,\n bite: this.bite,\n };\n }\n\n setViewerPrivateKey(privateKey: Hex): void {\n this.viewerPrivateKey = privateKey;\n }\n\n // --- Standard ERC-20 reads ---\n\n async name(): Promise<string> {\n return (await this.client.readContract({\n address: this.address,\n abi: confidentialWrapperAbi,\n functionName: \"name\",\n })) as string;\n }\n\n async symbol(): Promise<string> {\n return (await this.client.readContract({\n address: this.address,\n abi: confidentialWrapperAbi,\n functionName: \"symbol\",\n })) as string;\n }\n\n async decimals(): Promise<number> {\n return Number(\n await this.client.readContract({\n address: this.address,\n abi: confidentialWrapperAbi,\n functionName: \"decimals\",\n }),\n );\n }\n\n async allowance(owner: Hex, spender: Hex): Promise<bigint> {\n return (await this.client.readContract({\n address: this.address,\n abi: confidentialWrapperAbi,\n functionName: \"allowance\",\n args: [owner, spender],\n })) as bigint;\n }\n\n // --- Privacy-specific reads ---\n\n async viewerAddress(): Promise<Hex> {\n return (await this.client.readContract({\n address: this.address,\n abi: confidentialWrapperAbi,\n functionName: \"viewerAddresses\",\n args: [this.signer.address],\n })) as Hex;\n }\n\n async decryptBalance(): Promise<bigint> {\n if (!this.viewerPrivateKey) {\n throw new Error(\"Viewer key is required to decrypt balance.\");\n }\n return actions.decryptTokenBalance(this.actionConfig, { viewerKey: this.viewerPrivateKey });\n }\n\n // --- Standard ERC-20 writes ---\n\n async approve(spender: Hex, amount: bigint): Promise<Hex> {\n return actions.approve(this.actionConfig, { spender, amount });\n }\n\n // --- Privacy-specific writes ---\n\n transfer(to: Hex, amount: bigint): CtxPromise {\n return createCtxPromise(\n actions.transfer(this.actionConfig, { to, amount }),\n this.client,\n );\n }\n\n // --- Viewer key management ---\n\n async registerViewerPublicKey(publicKey: Hex): Promise<Hex> {\n return actions.registerViewerKey(this.actionConfig, { publicKey });\n }\n\n async authorizeHistoricViewForRange(\n address: Hex,\n fromTimestamp: bigint,\n toTimestamp: bigint,\n ): Promise<Hex> {\n return actions.authorizeHistoricViewForRange(this.actionConfig, {\n address,\n fromTimestamp,\n toTimestamp,\n });\n }\n\n async authorizeHistoricViewForTransfer(address: Hex, transferId: bigint): Promise<Hex> {\n return actions.authorizeHistoricViewForTransfer(this.actionConfig, { address, transferId });\n }\n\n async revokeHistoricView(address: Hex): Promise<Hex> {\n return actions.revokeHistoricView(this.actionConfig, { address });\n }\n\n // --- Decrypt / history ---\n\n async requestTransferDecryption(ctxHash: Hex): Promise<TransferData> {\n if (!this.viewerPrivateKey) {\n throw new Error(\"Viewer key is required to decrypt transfer data.\");\n }\n const txHash = await actions.requestTransferDecryption(this.actionConfig, { ctxHash });\n const { ctxReceipt } = await waitForCtx(txHash, this.client);\n const events = parseEventLogs({\n abi: confidentialWrapperAbi,\n logs: ctxReceipt.logs,\n eventName: \"ReEncryptedTransfer\",\n });\n const event = events[0];\n if (!event) {\n throw new Error(\"CTX receipt does not contain a ReEncryptedTransfer event.\");\n }\n const encryptedData = (event.args as { encryptedTransfer?: Hex }).encryptedTransfer;\n if (!encryptedData) {\n throw new Error(\"CTX receipt does not contain a ReEncryptedTransfer event.\");\n }\n return actions.decryptHistoricTransferData({ encryptedData, viewerKey: this.viewerPrivateKey });\n }\n}\n","import type { Hex } from \"viem\";\n\nimport { ConfidentialToken } from \"./ConfidentialToken.js\";\nimport { confidentialWrapperAbi } from \"./abi/confidentialWrapper.js\";\nimport * as actions from \"./actions/index.js\";\nimport { createCtxPromise, type CtxPromise } from \"./utils/ctx.js\";\n\nexport class ConfidentialWrapper extends ConfidentialToken {\n async underlying(): Promise<Hex> {\n return (await this.client.readContract({\n address: this.address,\n abi: confidentialWrapperAbi,\n functionName: \"underlying\",\n })) as Hex;\n }\n\n wrap(receiver: Hex, amount: bigint): CtxPromise {\n return createCtxPromise(actions.wrap(this.actionConfig, { receiver, amount }), this.client);\n }\n\n unwrap(receiver: Hex, amount: bigint): CtxPromise {\n return createCtxPromise(actions.unwrap(this.actionConfig, { receiver, amount }), this.client);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,oBAAoB,MAAM,sBAAmD;AACtF,SAAS,YAAY;AAQd,IAAM,oBAAN,MAAwB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EAID;AAAA,EACE;AAAA,EACF;AAAA,EAER,YAAY,QAAiC;AAC3C,SAAK,SAAS,OAAO;AACrB,SAAK,UAAU,OAAO;AACtB,SAAK,SAAS,OAAO;AACrB,SAAK,mBAAmB,OAAO;AAC/B,SAAK,SAAS,mBAAmB,EAAE,WAAW,KAAK,OAAO,MAAM,EAAE,CAAC;AACnE,SAAK,OAAO,IAAI,KAAK,OAAO,MAAM;AAAA,EACpC;AAAA,EAEA,IAAc,eAA6B;AACzC,WAAO;AAAA,MACL,QAAQ,KAAK;AAAA,MACb,SAAS,KAAK;AAAA,MACd,cAAc,KAAK;AAAA,MACnB,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK;AAAA,IACb;AAAA,EACF;AAAA,EAEA,oBAAoB,YAAuB;AACzC,SAAK,mBAAmB;AAAA,EAC1B;AAAA;AAAA,EAIA,MAAM,OAAwB;AAC5B,WAAQ,MAAM,KAAK,OAAO,aAAa;AAAA,MACrC,SAAS,KAAK;AAAA,MACd,KAAK;AAAA,MACL,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,SAA0B;AAC9B,WAAQ,MAAM,KAAK,OAAO,aAAa;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AC5F;AAAA,EAEA,OAAO,UAAe,QAA4B;AAChD,WAAO,iBAAyB,OAAO,KAAK,cAAc,EAAE,UAAU,OAAO,CAAC,GAAG,KAAK,MAAM;AAAA,EAC9F;AACF;","names":[]}
@@ -0,0 +1,60 @@
1
+ import { Hex, PublicClient } from 'viem';
2
+ import { BITE } from '@skalenetwork/bite';
3
+ import { S as Signer } from './types-WaeCtQlG.cjs';
4
+
5
+ type ActionConfig = {
6
+ rpcUrl: string;
7
+ address: Hex;
8
+ publicClient: PublicClient;
9
+ signer: Signer;
10
+ bite: BITE;
11
+ };
12
+ type TransferParams = {
13
+ to: Hex;
14
+ amount: bigint;
15
+ };
16
+ type WrapParams = {
17
+ receiver: Hex;
18
+ amount: bigint;
19
+ };
20
+ type UnwrapParams = {
21
+ receiver: Hex;
22
+ amount: bigint;
23
+ };
24
+ type ApproveParams = {
25
+ spender: Hex;
26
+ amount: bigint;
27
+ };
28
+ type TopUpParams = {
29
+ amount: bigint;
30
+ };
31
+ type RegisterViewerKeyParams = {
32
+ publicKey: Hex;
33
+ };
34
+ type AuthorizeHistoricViewForRangeParams = {
35
+ address: Hex;
36
+ fromTimestamp: bigint;
37
+ toTimestamp: bigint;
38
+ };
39
+ type AuthorizeHistoricViewForTransferParams = {
40
+ address: Hex;
41
+ transferId: bigint;
42
+ };
43
+ type RevokeHistoricViewParams = {
44
+ address: Hex;
45
+ };
46
+ type GetTransferIdParams = {
47
+ ctxHash: Hex;
48
+ };
49
+ type RequestTransferDecryptionParams = {
50
+ ctxHash: Hex;
51
+ };
52
+ type DecryptHistoricTransferDataParams = {
53
+ encryptedData: Hex;
54
+ viewerKey: Hex;
55
+ };
56
+ type DecryptBalanceParams = {
57
+ viewerKey: Hex;
58
+ };
59
+
60
+ export type { ActionConfig as A, DecryptHistoricTransferDataParams as D, GetTransferIdParams as G, RegisterViewerKeyParams as R, TransferParams as T, UnwrapParams as U, WrapParams as W, ApproveParams as a, TopUpParams as b, DecryptBalanceParams as c, AuthorizeHistoricViewForRangeParams as d, AuthorizeHistoricViewForTransferParams as e, RequestTransferDecryptionParams as f, RevokeHistoricViewParams as g };
@@ -0,0 +1,60 @@
1
+ import { Hex, PublicClient } from 'viem';
2
+ import { BITE } from '@skalenetwork/bite';
3
+ import { S as Signer } from './types-WaeCtQlG.js';
4
+
5
+ type ActionConfig = {
6
+ rpcUrl: string;
7
+ address: Hex;
8
+ publicClient: PublicClient;
9
+ signer: Signer;
10
+ bite: BITE;
11
+ };
12
+ type TransferParams = {
13
+ to: Hex;
14
+ amount: bigint;
15
+ };
16
+ type WrapParams = {
17
+ receiver: Hex;
18
+ amount: bigint;
19
+ };
20
+ type UnwrapParams = {
21
+ receiver: Hex;
22
+ amount: bigint;
23
+ };
24
+ type ApproveParams = {
25
+ spender: Hex;
26
+ amount: bigint;
27
+ };
28
+ type TopUpParams = {
29
+ amount: bigint;
30
+ };
31
+ type RegisterViewerKeyParams = {
32
+ publicKey: Hex;
33
+ };
34
+ type AuthorizeHistoricViewForRangeParams = {
35
+ address: Hex;
36
+ fromTimestamp: bigint;
37
+ toTimestamp: bigint;
38
+ };
39
+ type AuthorizeHistoricViewForTransferParams = {
40
+ address: Hex;
41
+ transferId: bigint;
42
+ };
43
+ type RevokeHistoricViewParams = {
44
+ address: Hex;
45
+ };
46
+ type GetTransferIdParams = {
47
+ ctxHash: Hex;
48
+ };
49
+ type RequestTransferDecryptionParams = {
50
+ ctxHash: Hex;
51
+ };
52
+ type DecryptHistoricTransferDataParams = {
53
+ encryptedData: Hex;
54
+ viewerKey: Hex;
55
+ };
56
+ type DecryptBalanceParams = {
57
+ viewerKey: Hex;
58
+ };
59
+
60
+ export type { ActionConfig as A, DecryptHistoricTransferDataParams as D, GetTransferIdParams as G, RegisterViewerKeyParams as R, TransferParams as T, UnwrapParams as U, WrapParams as W, ApproveParams as a, TopUpParams as b, DecryptBalanceParams as c, AuthorizeHistoricViewForRangeParams as d, AuthorizeHistoricViewForTransferParams as e, RequestTransferDecryptionParams as f, RevokeHistoricViewParams as g };
@@ -0,0 +1,32 @@
1
+ import { Hex } from 'viem';
2
+
3
+ type Signer = {
4
+ address: Hex;
5
+ sendTransaction(tx: UnsignedTx): Promise<Hex>;
6
+ };
7
+ type UnsignedTx = {
8
+ to: Hex;
9
+ data: Hex;
10
+ value?: bigint;
11
+ };
12
+ type ViewerKeypair = {
13
+ privateKey: Hex;
14
+ publicKey: Hex;
15
+ x: Hex;
16
+ y: Hex;
17
+ };
18
+ type TransferData = {
19
+ from: Hex;
20
+ to: Hex;
21
+ value: bigint;
22
+ timestamp: bigint;
23
+ transferId: bigint;
24
+ };
25
+ type ConfidentialTokenConfig = {
26
+ rpcUrl: string;
27
+ address: Hex;
28
+ signer: Signer;
29
+ viewerPrivateKey?: Hex;
30
+ };
31
+
32
+ export type { ConfidentialTokenConfig as C, Signer as S, TransferData as T, UnsignedTx as U, ViewerKeypair as V };
@@ -0,0 +1,32 @@
1
+ import { Hex } from 'viem';
2
+
3
+ type Signer = {
4
+ address: Hex;
5
+ sendTransaction(tx: UnsignedTx): Promise<Hex>;
6
+ };
7
+ type UnsignedTx = {
8
+ to: Hex;
9
+ data: Hex;
10
+ value?: bigint;
11
+ };
12
+ type ViewerKeypair = {
13
+ privateKey: Hex;
14
+ publicKey: Hex;
15
+ x: Hex;
16
+ y: Hex;
17
+ };
18
+ type TransferData = {
19
+ from: Hex;
20
+ to: Hex;
21
+ value: bigint;
22
+ timestamp: bigint;
23
+ transferId: bigint;
24
+ };
25
+ type ConfidentialTokenConfig = {
26
+ rpcUrl: string;
27
+ address: Hex;
28
+ signer: Signer;
29
+ viewerPrivateKey?: Hex;
30
+ };
31
+
32
+ export type { ConfidentialTokenConfig as C, Signer as S, TransferData as T, UnsignedTx as U, ViewerKeypair as V };
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/index.ts
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ decryptBalance: () => decryptBalance,
24
+ decryptEciesPayload: () => decryptEciesPayload,
25
+ decryptTransferData: () => decryptTransferData,
26
+ deriveAddressFromPublicKey: () => deriveAddressFromPublicKey,
27
+ deriveViewerKeypair: () => deriveViewerKeypair,
28
+ getCtxHash: () => getCtxHash,
29
+ getCtxHashes: () => getCtxHashes,
30
+ parsePublicKeyCoordinates: () => parsePublicKeyCoordinates,
31
+ validateViewerKey: () => validateViewerKey,
32
+ waitForCtx: () => waitForCtx
33
+ });
34
+ module.exports = __toCommonJS(utils_exports);
35
+
36
+ // src/utils/ctx.ts
37
+ function normalizeHex(value) {
38
+ const trimmed = value.trim();
39
+ if (/^0x[0-9a-fA-F]+$/.test(trimmed)) {
40
+ return trimmed;
41
+ }
42
+ if (/^[0-9a-fA-F]+$/.test(trimmed)) {
43
+ return `0x${trimmed}`;
44
+ }
45
+ return void 0;
46
+ }
47
+ function findFirstHex(value) {
48
+ if (typeof value === "string") {
49
+ return normalizeHex(value);
50
+ }
51
+ if (Array.isArray(value)) {
52
+ for (const item of value) {
53
+ const candidate = findFirstHex(item);
54
+ if (candidate) {
55
+ return candidate;
56
+ }
57
+ }
58
+ return void 0;
59
+ }
60
+ if (value && typeof value === "object") {
61
+ for (const child of Object.values(value)) {
62
+ const candidate = findFirstHex(child);
63
+ if (candidate) {
64
+ return candidate;
65
+ }
66
+ }
67
+ }
68
+ return void 0;
69
+ }
70
+ function collectHexValues(value, acc) {
71
+ if (typeof value === "string") {
72
+ const normalized = normalizeHex(value);
73
+ if (normalized) {
74
+ acc.push(normalized);
75
+ }
76
+ return;
77
+ }
78
+ if (Array.isArray(value)) {
79
+ for (const item of value) {
80
+ collectHexValues(item, acc);
81
+ }
82
+ return;
83
+ }
84
+ if (value && typeof value === "object") {
85
+ for (const child of Object.values(value)) {
86
+ collectHexValues(child, acc);
87
+ }
88
+ }
89
+ }
90
+ async function callBiteGetCraftedCtxs(publicClient, txHash) {
91
+ return publicClient.request({
92
+ method: "bite_getCraftedCtxs",
93
+ params: [txHash]
94
+ });
95
+ }
96
+ async function getCtxHash(publicClient, txHash) {
97
+ const result = await callBiteGetCraftedCtxs(publicClient, txHash);
98
+ return findFirstHex(result);
99
+ }
100
+ async function getCtxHashes(publicClient, txHash) {
101
+ const result = await callBiteGetCraftedCtxs(publicClient, txHash);
102
+ const allHexes = [];
103
+ collectHexValues(result, allHexes);
104
+ const deduped = /* @__PURE__ */ new Map();
105
+ for (const hash of allHexes) {
106
+ deduped.set(hash.toLowerCase(), hash);
107
+ }
108
+ return Array.from(deduped.values());
109
+ }
110
+ async function waitForCtx(txHash, publicClient) {
111
+ const originReceipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
112
+ const ctxHash = await getCtxHash(publicClient, txHash);
113
+ if (!ctxHash) {
114
+ throw new Error(`No crafted CTX found for tx ${txHash}.`);
115
+ }
116
+ const ctxReceipt = await publicClient.waitForTransactionReceipt({ hash: ctxHash });
117
+ return { originHash: txHash, originReceipt, ctxHash, ctxReceipt };
118
+ }
119
+
120
+ // src/utils/crypto.ts
121
+ var import_secp256k1 = require("@noble/curves/secp256k1");
122
+ var import_sha256 = require("@noble/hashes/sha256");
123
+ var import_aes = require("@noble/ciphers/aes");
124
+ var import_viem = require("viem");
125
+ function bytesToBigInt(bytes) {
126
+ if (bytes.length === 0) {
127
+ return 0n;
128
+ }
129
+ const hexValue = (0, import_viem.bytesToHex)(bytes);
130
+ return BigInt(hexValue === "0x" ? "0x0" : hexValue);
131
+ }
132
+ function decryptEciesPayload(encryptedHex, privateKey) {
133
+ const payload = (0, import_viem.hexToBytes)(encryptedHex);
134
+ if (payload.length < 65) {
135
+ throw new Error("Encrypted payload is too short.");
136
+ }
137
+ const iv = payload.slice(0, 16);
138
+ const ephemeralCompressedPublicKey = payload.slice(16, 49);
139
+ const ciphertext = payload.slice(49);
140
+ if (ephemeralCompressedPublicKey.length !== 33) {
141
+ throw new Error("Invalid ephemeral public key length in encrypted payload.");
142
+ }
143
+ if (ciphertext.length === 0 || ciphertext.length % 16 !== 0) {
144
+ throw new Error("Invalid AES-CBC ciphertext length.");
145
+ }
146
+ const sharedSecret = import_secp256k1.secp256k1.getSharedSecret(
147
+ (0, import_viem.hexToBytes)(privateKey),
148
+ ephemeralCompressedPublicKey,
149
+ true
150
+ );
151
+ const encryptionKey = (0, import_sha256.sha256)(sharedSecret.slice(1));
152
+ const keyMaterial = Uint8Array.from(encryptionKey);
153
+ return (0, import_aes.cbc)(keyMaterial, iv).decrypt(ciphertext);
154
+ }
155
+ function tryDecodeTransferData(encoded) {
156
+ try {
157
+ const [from, to, value, timestamp, transferId] = (0, import_viem.decodeAbiParameters)(
158
+ [
159
+ { type: "address" },
160
+ { type: "address" },
161
+ { type: "uint256" },
162
+ { type: "uint256" },
163
+ { type: "uint256" }
164
+ ],
165
+ encoded
166
+ );
167
+ return { from, to, value, timestamp, transferId };
168
+ } catch {
169
+ return void 0;
170
+ }
171
+ }
172
+ async function decryptBalance(encryptedHex, privateKey) {
173
+ const plaintext = decryptEciesPayload(encryptedHex, privateKey);
174
+ if (plaintext.length <= 32) {
175
+ return bytesToBigInt(plaintext);
176
+ }
177
+ return bytesToBigInt(plaintext.slice(-32));
178
+ }
179
+ async function decryptTransferData(encryptedHex, privateKey) {
180
+ const plaintext = decryptEciesPayload(encryptedHex, privateKey);
181
+ const direct = tryDecodeTransferData((0, import_viem.bytesToHex)(plaintext));
182
+ if (direct) {
183
+ return direct;
184
+ }
185
+ const structSizeBytes = 32 * 5;
186
+ if (plaintext.length >= structSizeBytes) {
187
+ const trailing = plaintext.slice(-structSizeBytes);
188
+ const trailingDecoded = tryDecodeTransferData((0, import_viem.bytesToHex)(trailing));
189
+ if (trailingDecoded) {
190
+ return trailingDecoded;
191
+ }
192
+ }
193
+ throw new Error("Unable to decode decrypted transfer payload as TransferData struct.");
194
+ }
195
+
196
+ // src/utils/viewerKey.ts
197
+ var import_viem2 = require("viem");
198
+ var import_utils = require("viem/utils");
199
+ var import_secp256k12 = require("@noble/curves/secp256k1");
200
+ function privateKeyFromSignature(signature) {
201
+ let candidate = (0, import_viem2.keccak256)((0, import_viem2.hexToBytes)(signature));
202
+ for (let i = 0; i < 16; i += 1) {
203
+ if (import_secp256k12.secp256k1.utils.isValidSecretKey((0, import_viem2.hexToBytes)(candidate))) {
204
+ return candidate;
205
+ }
206
+ candidate = (0, import_viem2.keccak256)((0, import_viem2.hexToBytes)(candidate));
207
+ }
208
+ throw new Error("Unable to derive a valid deterministic private key from signature.");
209
+ }
210
+ function parsePublicKeyCoordinates(publicKey) {
211
+ const raw = publicKey.startsWith("0x04") ? publicKey.slice(4) : publicKey.slice(2);
212
+ if (raw.length !== 128) {
213
+ throw new Error("Public key must be an uncompressed key (65 bytes with 0x04 prefix).");
214
+ }
215
+ return {
216
+ x: `0x${raw.slice(0, 64)}`,
217
+ y: `0x${raw.slice(64, 128)}`
218
+ };
219
+ }
220
+ function deriveAddressFromPublicKey(publicKey) {
221
+ const key = publicKey.startsWith("0x04") ? publicKey : `0x04${publicKey.slice(2)}`;
222
+ return (0, import_utils.publicKeyToAddress)(key);
223
+ }
224
+ function validateViewerKey(publicKey, expectedViewerAddress) {
225
+ if (!expectedViewerAddress) {
226
+ return void 0;
227
+ }
228
+ if ((0, import_viem2.isAddressEqual)(expectedViewerAddress, import_viem2.zeroAddress)) {
229
+ return void 0;
230
+ }
231
+ const derivedViewerAddress = deriveAddressFromPublicKey(publicKey);
232
+ if (!(0, import_viem2.isAddressEqual)(derivedViewerAddress, expectedViewerAddress)) {
233
+ return "Public key does not match the registered viewer address.";
234
+ }
235
+ return void 0;
236
+ }
237
+ function deriveViewerKeypair(signature) {
238
+ const privateKey = privateKeyFromSignature(signature);
239
+ const publicKey = (0, import_viem2.toHex)(import_secp256k12.secp256k1.getPublicKey((0, import_viem2.hexToBytes)(privateKey), false));
240
+ const { x, y } = parsePublicKeyCoordinates(publicKey);
241
+ return { privateKey, publicKey, x, y };
242
+ }
243
+ // Annotate the CommonJS export names for ESM import in node:
244
+ 0 && (module.exports = {
245
+ decryptBalance,
246
+ decryptEciesPayload,
247
+ decryptTransferData,
248
+ deriveAddressFromPublicKey,
249
+ deriveViewerKeypair,
250
+ getCtxHash,
251
+ getCtxHashes,
252
+ parsePublicKeyCoordinates,
253
+ validateViewerKey,
254
+ waitForCtx
255
+ });
256
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/index.ts","../../src/utils/ctx.ts","../../src/utils/crypto.ts","../../src/utils/viewerKey.ts"],"sourcesContent":["export { getCtxHash, getCtxHashes, waitForCtx } from \"./ctx.js\";\nexport type { CtxResult, CtxPromise } from \"./ctx.js\";\nexport { decryptBalance, decryptTransferData, decryptEciesPayload } from \"./crypto.js\";\nexport {\n deriveViewerKeypair,\n parsePublicKeyCoordinates,\n deriveAddressFromPublicKey,\n validateViewerKey,\n} from \"./viewerKey.js\";\n","import type { Hex, PublicClient, TransactionReceipt } from \"viem\";\n\nexport type CtxResult = {\n originHash: Hex;\n originReceipt: TransactionReceipt;\n ctxHash: Hex;\n ctxReceipt: TransactionReceipt;\n};\n\nexport type CtxPromise = Promise<Hex> & {\n waitForCtx(): Promise<CtxResult>;\n};\n\nexport function createCtxPromise(\n txHashPromise: Promise<Hex>,\n publicClient: PublicClient,\n): CtxPromise {\n const promise = txHashPromise as CtxPromise;\n promise.waitForCtx = async () => {\n const txHash = await txHashPromise;\n return waitForCtx(txHash, publicClient);\n };\n return promise;\n}\n\nfunction normalizeHex(value: string): Hex | undefined {\n const trimmed = value.trim();\n\n if (/^0x[0-9a-fA-F]+$/.test(trimmed)) {\n return trimmed as Hex;\n }\n\n if (/^[0-9a-fA-F]+$/.test(trimmed)) {\n return `0x${trimmed}` as Hex;\n }\n\n return undefined;\n}\n\nfunction findFirstHex(value: unknown): Hex | undefined {\n if (typeof value === \"string\") {\n return normalizeHex(value);\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n const candidate = findFirstHex(item);\n if (candidate) {\n return candidate;\n }\n }\n return undefined;\n }\n\n if (value && typeof value === \"object\") {\n for (const child of Object.values(value)) {\n const candidate = findFirstHex(child);\n if (candidate) {\n return candidate;\n }\n }\n }\n\n return undefined;\n}\n\nfunction collectHexValues(value: unknown, acc: Hex[]): void {\n if (typeof value === \"string\") {\n const normalized = normalizeHex(value);\n if (normalized) {\n acc.push(normalized);\n }\n return;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n collectHexValues(item, acc);\n }\n return;\n }\n\n if (value && typeof value === \"object\") {\n for (const child of Object.values(value)) {\n collectHexValues(child, acc);\n }\n }\n}\n\nasync function callBiteGetCraftedCtxs(publicClient: PublicClient, txHash: Hex): Promise<unknown> {\n return publicClient.request({\n method: \"bite_getCraftedCtxs\" as any,\n params: [txHash] as any,\n });\n}\n\nexport async function getCtxHash(\n publicClient: PublicClient,\n txHash: Hex,\n): Promise<Hex | undefined> {\n const result = await callBiteGetCraftedCtxs(publicClient, txHash);\n return findFirstHex(result);\n}\n\nexport async function getCtxHashes(publicClient: PublicClient, txHash: Hex): Promise<Hex[]> {\n const result = await callBiteGetCraftedCtxs(publicClient, txHash);\n const allHexes: Hex[] = [];\n collectHexValues(result, allHexes);\n\n const deduped = new Map<string, Hex>();\n for (const hash of allHexes) {\n deduped.set(hash.toLowerCase(), hash);\n }\n\n return Array.from(deduped.values());\n}\n\nexport async function waitForCtx(txHash: Hex, publicClient: PublicClient): Promise<CtxResult> {\n // 1. Wait for original tx to be mined\n const originReceipt = await publicClient.waitForTransactionReceipt({ hash: txHash });\n\n // 2. Get CTX hash (deterministic once origin is mined)\n const ctxHash = await getCtxHash(publicClient, txHash);\n if (!ctxHash) {\n throw new Error(`No crafted CTX found for tx ${txHash}.`);\n }\n\n // 3. Wait for CTX to be mined\n const ctxReceipt = await publicClient.waitForTransactionReceipt({ hash: ctxHash });\n\n return { originHash: txHash, originReceipt, ctxHash, ctxReceipt };\n}\n","import { secp256k1 } from \"@noble/curves/secp256k1\";\nimport { sha256 } from \"@noble/hashes/sha256\";\nimport { cbc } from \"@noble/ciphers/aes\";\nimport { bytesToHex, decodeAbiParameters, hexToBytes, type Hex } from \"viem\";\n\nimport type { TransferData } from \"../types.js\";\n\nfunction bytesToBigInt(bytes: Uint8Array): bigint {\n if (bytes.length === 0) {\n return 0n;\n }\n const hexValue = bytesToHex(bytes);\n return BigInt(hexValue === \"0x\" ? \"0x0\" : hexValue);\n}\n\nexport function decryptEciesPayload(encryptedHex: Hex, privateKey: Hex): Uint8Array {\n const payload = hexToBytes(encryptedHex);\n\n if (payload.length < 65) {\n throw new Error(\"Encrypted payload is too short.\");\n }\n\n const iv = payload.slice(0, 16);\n const ephemeralCompressedPublicKey = payload.slice(16, 49);\n const ciphertext = payload.slice(49);\n\n if (ephemeralCompressedPublicKey.length !== 33) {\n throw new Error(\"Invalid ephemeral public key length in encrypted payload.\");\n }\n\n if (ciphertext.length === 0 || ciphertext.length % 16 !== 0) {\n throw new Error(\"Invalid AES-CBC ciphertext length.\");\n }\n\n const sharedSecret = secp256k1.getSharedSecret(\n hexToBytes(privateKey),\n ephemeralCompressedPublicKey,\n true,\n );\n const encryptionKey = sha256(sharedSecret.slice(1));\n const keyMaterial = Uint8Array.from(encryptionKey);\n\n return cbc(keyMaterial, iv).decrypt(ciphertext);\n}\n\nfunction tryDecodeTransferData(encoded: Hex): TransferData | undefined {\n try {\n const [from, to, value, timestamp, transferId] = decodeAbiParameters(\n [\n { type: \"address\" },\n { type: \"address\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n { type: \"uint256\" },\n ],\n encoded,\n );\n\n return { from, to, value, timestamp, transferId };\n } catch {\n return undefined;\n }\n}\n\nexport async function decryptBalance(encryptedHex: Hex, privateKey: Hex): Promise<bigint> {\n const plaintext = decryptEciesPayload(encryptedHex, privateKey);\n\n if (plaintext.length <= 32) {\n return bytesToBigInt(plaintext);\n }\n\n return bytesToBigInt(plaintext.slice(-32));\n}\n\nexport async function decryptTransferData(\n encryptedHex: Hex,\n privateKey: Hex,\n): Promise<TransferData> {\n const plaintext = decryptEciesPayload(encryptedHex, privateKey);\n\n const direct = tryDecodeTransferData(bytesToHex(plaintext));\n if (direct) {\n return direct;\n }\n\n const structSizeBytes = 32 * 5;\n if (plaintext.length >= structSizeBytes) {\n const trailing = plaintext.slice(-structSizeBytes);\n const trailingDecoded = tryDecodeTransferData(bytesToHex(trailing));\n if (trailingDecoded) {\n return trailingDecoded;\n }\n }\n\n throw new Error(\"Unable to decode decrypted transfer payload as TransferData struct.\");\n}\n","import { type Hex, hexToBytes, isAddressEqual, keccak256, toHex, zeroAddress } from \"viem\";\nimport { publicKeyToAddress } from \"viem/utils\";\nimport { secp256k1 } from \"@noble/curves/secp256k1\";\n\nimport type { ViewerKeypair } from \"../types.js\";\n\nfunction privateKeyFromSignature(signature: Hex): Hex {\n let candidate = keccak256(hexToBytes(signature));\n\n for (let i = 0; i < 16; i += 1) {\n if (secp256k1.utils.isValidSecretKey(hexToBytes(candidate))) {\n return candidate;\n }\n candidate = keccak256(hexToBytes(candidate));\n }\n\n throw new Error(\"Unable to derive a valid deterministic private key from signature.\");\n}\n\nexport function parsePublicKeyCoordinates(publicKey: Hex): { x: Hex; y: Hex } {\n const raw = publicKey.startsWith(\"0x04\") ? publicKey.slice(4) : publicKey.slice(2);\n\n if (raw.length !== 128) {\n throw new Error(\"Public key must be an uncompressed key (65 bytes with 0x04 prefix).\");\n }\n\n return {\n x: `0x${raw.slice(0, 64)}` as Hex,\n y: `0x${raw.slice(64, 128)}` as Hex,\n };\n}\n\nexport function deriveAddressFromPublicKey(publicKey: Hex): Hex {\n const key = publicKey.startsWith(\"0x04\") ? publicKey : (`0x04${publicKey.slice(2)}` as Hex);\n return publicKeyToAddress(key) as Hex;\n}\n\nexport function validateViewerKey(publicKey: Hex, expectedViewerAddress?: Hex): string | undefined {\n if (!expectedViewerAddress) {\n return undefined;\n }\n\n if (isAddressEqual(expectedViewerAddress, zeroAddress)) {\n return undefined;\n }\n\n const derivedViewerAddress = deriveAddressFromPublicKey(publicKey);\n if (!isAddressEqual(derivedViewerAddress, expectedViewerAddress)) {\n return \"Public key does not match the registered viewer address.\";\n }\n\n return undefined;\n}\n\nexport function deriveViewerKeypair(signature: Hex): ViewerKeypair {\n const privateKey = privateKeyFromSignature(signature);\n const publicKey = toHex(secp256k1.getPublicKey(hexToBytes(privateKey), false));\n const { x, y } = parsePublicKeyCoordinates(publicKey);\n\n return { privateKey, publicKey, x, y };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACyBA,SAAS,aAAa,OAAgC;AACpD,QAAM,UAAU,MAAM,KAAK;AAE3B,MAAI,mBAAmB,KAAK,OAAO,GAAG;AACpC,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB,KAAK,OAAO,GAAG;AAClC,WAAO,KAAK,OAAO;AAAA,EACrB;AAEA,SAAO;AACT;AAEA,SAAS,aAAa,OAAiC;AACrD,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,aAAa,KAAK;AAAA,EAC3B;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,eAAW,QAAQ,OAAO;AACxB,YAAM,YAAY,aAAa,I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aAAO;AAAA,IACT;AACA,oBAAY,4BAAU,yBAAW,SAAS,CAAC;AAAA,EAC7C;AAEA,QAAM,IAAI,MAAM,oEAAoE;AACtF;AAEO,SAAS,0BAA0B,WAAoC;AAC5E,QAAM,MAAM,UAAU,WAAW,MAAM,IAAI,UAAU,MAAM,CAAC,IAAI,UAAU,MAAM,CAAC;AAEjF,MAAI,IAAI,WAAW,KAAK;AACtB,UAAM,IAAI,MAAM,qEAAqE;AAAA,EACvF;AAEA,SAAO;AAAA,IACL,GAAG,KAAK,IAAI,MAAM,GAAG,EAAE,CAAC;AAAA,IACxB,GAAG,KAAK,IAAI,MAAM,IAAI,GAAG,CAAC;AAAA,EAC5B;AACF;AAEO,SAAS,2BAA2B,WAAqB;AAC9D,QAAM,MAAM,UAAU,WAAW,MAAM,IAAI,YAAa,OAAO,UAAU,MAAM,CAAC,CAAC;AACjF,aAAO,iCAAmB,GAAG;AAC/B;AAEO,SAAS,kBAAkB,WAAgB,uBAAiD;AACjG,MAAI,CAAC,uBAAuB;AAC1B,WAAO;AAAA,EACT;AAEA,UAAI,6BAAe,uBAAuB,wBAAW,GAAG;AACtD,WAAO;AAAA,EACT;AAEA,QAAM,uBAAuB,2BAA2B,SAAS;AACjE,MAAI,KAAC,6BAAe,sBAAsB,qBAAqB,GAAG;AAChE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,SAAS,oBAAoB,WAA+B;AACjE,QAAM,aAAa,wBAAwB,SAAS;AACpD,QAAM,gBAAY,oBAAM,4BAAU,iBAAa,yBAAW,UAAU,GAAG,KAAK,CAAC;AAC7E,QAAM,EAAE,GAAG,EAAE,IAAI,0BAA0B,SAAS;AAEpD,SAAO,EAAE,YAAY,WAAW,GAAG,EAAE;AACvC;","names":["import_viem","import_secp256k1"]}
@@ -0,0 +1,17 @@
1
+ export { C as CtxPromise, a as CtxResult, g as getCtxHash, b as getCtxHashes, w as waitForCtx } from '../ctx-ifn_jhPL.cjs';
2
+ import { Hex } from 'viem';
3
+ import { T as TransferData, V as ViewerKeypair } from '../types-WaeCtQlG.cjs';
4
+
5
+ declare function decryptEciesPayload(encryptedHex: Hex, privateKey: Hex): Uint8Array;
6
+ declare function decryptBalance(encryptedHex: Hex, privateKey: Hex): Promise<bigint>;
7
+ declare function decryptTransferData(encryptedHex: Hex, privateKey: Hex): Promise<TransferData>;
8
+
9
+ declare function parsePublicKeyCoordinates(publicKey: Hex): {
10
+ x: Hex;
11
+ y: Hex;
12
+ };
13
+ declare function deriveAddressFromPublicKey(publicKey: Hex): Hex;
14
+ declare function validateViewerKey(publicKey: Hex, expectedViewerAddress?: Hex): string | undefined;
15
+ declare function deriveViewerKeypair(signature: Hex): ViewerKeypair;
16
+
17
+ export { decryptBalance, decryptEciesPayload, decryptTransferData, deriveAddressFromPublicKey, deriveViewerKeypair, parsePublicKeyCoordinates, validateViewerKey };