zkenclave-sdk 0.1.18 → 0.1.21
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.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +66 -1
- package/dist/index.mjs +66 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -113,6 +113,8 @@ declare class PrivacyVaultSDK {
|
|
|
113
113
|
connect(signer: ethers.Signer): Promise<void>;
|
|
114
114
|
deposit(amount: bigint): Promise<DepositResult>;
|
|
115
115
|
withdraw(note: DepositNote, recipient: string, complianceProof?: Uint8Array): Promise<WithdrawalResult>;
|
|
116
|
+
withdrawViaTEE(note: DepositNote, recipient: string, teeEndpoint?: string): Promise<WithdrawalResult>;
|
|
117
|
+
private serializeTEEAttestation;
|
|
116
118
|
getLatestRoot(): Promise<Uint8Array>;
|
|
117
119
|
getNextLeafIndex(): Promise<number>;
|
|
118
120
|
isNullifierUsed(nullifier: Uint8Array): Promise<boolean>;
|
|
@@ -150,7 +152,7 @@ declare class MerkleTree {
|
|
|
150
152
|
|
|
151
153
|
declare const MERKLE_TREE_DEPTH = 20;
|
|
152
154
|
declare const FIELD_SIZE: bigint;
|
|
153
|
-
declare const DEFAULT_GAS_LIMIT =
|
|
155
|
+
declare const DEFAULT_GAS_LIMIT = 3000000n;
|
|
154
156
|
declare const DEFAULT_BATCH_SIZE = 10;
|
|
155
157
|
declare const PROOF_EXPIRY_MS = 300000;
|
|
156
158
|
declare const CONTRACT_ADDRESSES: {
|
package/dist/index.d.ts
CHANGED
|
@@ -113,6 +113,8 @@ declare class PrivacyVaultSDK {
|
|
|
113
113
|
connect(signer: ethers.Signer): Promise<void>;
|
|
114
114
|
deposit(amount: bigint): Promise<DepositResult>;
|
|
115
115
|
withdraw(note: DepositNote, recipient: string, complianceProof?: Uint8Array): Promise<WithdrawalResult>;
|
|
116
|
+
withdrawViaTEE(note: DepositNote, recipient: string, teeEndpoint?: string): Promise<WithdrawalResult>;
|
|
117
|
+
private serializeTEEAttestation;
|
|
116
118
|
getLatestRoot(): Promise<Uint8Array>;
|
|
117
119
|
getNextLeafIndex(): Promise<number>;
|
|
118
120
|
isNullifierUsed(nullifier: Uint8Array): Promise<boolean>;
|
|
@@ -150,7 +152,7 @@ declare class MerkleTree {
|
|
|
150
152
|
|
|
151
153
|
declare const MERKLE_TREE_DEPTH = 20;
|
|
152
154
|
declare const FIELD_SIZE: bigint;
|
|
153
|
-
declare const DEFAULT_GAS_LIMIT =
|
|
155
|
+
declare const DEFAULT_GAS_LIMIT = 3000000n;
|
|
154
156
|
declare const DEFAULT_BATCH_SIZE = 10;
|
|
155
157
|
declare const PROOF_EXPIRY_MS = 300000;
|
|
156
158
|
declare const CONTRACT_ADDRESSES: {
|
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ var MERKLE_TREE_DEPTH = 20;
|
|
|
61
61
|
var FIELD_SIZE = BigInt(
|
|
62
62
|
"21888242871839275222246405745257275088548364400416034343698204186575808495617"
|
|
63
63
|
);
|
|
64
|
-
var DEFAULT_GAS_LIMIT =
|
|
64
|
+
var DEFAULT_GAS_LIMIT = 3000000n;
|
|
65
65
|
var DEFAULT_BATCH_SIZE = 10;
|
|
66
66
|
var PROOF_EXPIRY_MS = 3e5;
|
|
67
67
|
var CONTRACT_ADDRESSES = {
|
|
@@ -659,6 +659,71 @@ var PrivacyVaultSDK = class {
|
|
|
659
659
|
timestamp: Date.now()
|
|
660
660
|
};
|
|
661
661
|
}
|
|
662
|
+
async withdrawViaTEE(note, recipient, teeEndpoint = "/api/tee-withdraw") {
|
|
663
|
+
if (!this.signer) {
|
|
664
|
+
throw new Error("Signer required for withdrawals");
|
|
665
|
+
}
|
|
666
|
+
const root = await this.getLatestRoot();
|
|
667
|
+
const merklePath = this._merkleTree.generateProof(note.leafIndex);
|
|
668
|
+
const response = await fetch(teeEndpoint, {
|
|
669
|
+
method: "POST",
|
|
670
|
+
headers: { "Content-Type": "application/json" },
|
|
671
|
+
body: JSON.stringify({
|
|
672
|
+
commitment: Array.from(note.commitment),
|
|
673
|
+
nullifierSeed: Array.from(note.nullifierSeed),
|
|
674
|
+
secret: Array.from(note.secret),
|
|
675
|
+
amount: note.amount.toString(),
|
|
676
|
+
leafIndex: note.leafIndex,
|
|
677
|
+
recipient,
|
|
678
|
+
merklePath: merklePath.path.map((p) => Array.from(p)),
|
|
679
|
+
pathIndices: merklePath.indices,
|
|
680
|
+
merkleRoot: Array.from(root)
|
|
681
|
+
})
|
|
682
|
+
});
|
|
683
|
+
if (!response.ok) {
|
|
684
|
+
const error = await response.json();
|
|
685
|
+
throw new Error(error.error || "TEE withdrawal failed");
|
|
686
|
+
}
|
|
687
|
+
const result = await response.json();
|
|
688
|
+
if (!result.success) {
|
|
689
|
+
throw new Error(result.error || "TEE withdrawal failed");
|
|
690
|
+
}
|
|
691
|
+
const tx = await this.vault.withdraw(
|
|
692
|
+
result.nullifierHash,
|
|
693
|
+
bytesToHex(root),
|
|
694
|
+
recipient,
|
|
695
|
+
note.amount,
|
|
696
|
+
hexToBytes(result.zkProof),
|
|
697
|
+
this.serializeTEEAttestation(result.teeAttestation),
|
|
698
|
+
{ gasLimit: DEFAULT_GAS_LIMIT }
|
|
699
|
+
);
|
|
700
|
+
const receipt = await tx.wait();
|
|
701
|
+
return {
|
|
702
|
+
success: true,
|
|
703
|
+
txHash: receipt.hash,
|
|
704
|
+
zkProof: hexToBytes(result.zkProof),
|
|
705
|
+
nullifierHash: hexToBytes(result.nullifierHash),
|
|
706
|
+
merkleRoot: root,
|
|
707
|
+
timestamp: Date.now()
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
serializeTEEAttestation(attestation) {
|
|
711
|
+
const enclaveId = hexToBytes(attestation.enclaveId);
|
|
712
|
+
const dataHash = hexToBytes(attestation.dataHash);
|
|
713
|
+
const signature = hexToBytes(attestation.signature);
|
|
714
|
+
const timestampBytes = new Uint8Array(8);
|
|
715
|
+
new DataView(timestampBytes.buffer).setBigUint64(
|
|
716
|
+
0,
|
|
717
|
+
BigInt(attestation.timestamp),
|
|
718
|
+
false
|
|
719
|
+
);
|
|
720
|
+
return new Uint8Array([
|
|
721
|
+
...enclaveId,
|
|
722
|
+
...timestampBytes,
|
|
723
|
+
...dataHash,
|
|
724
|
+
...signature
|
|
725
|
+
]);
|
|
726
|
+
}
|
|
662
727
|
async getLatestRoot() {
|
|
663
728
|
const root = await this.readVault.getLatestRoot();
|
|
664
729
|
return hexToBytes(root);
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ var MERKLE_TREE_DEPTH = 20;
|
|
|
7
7
|
var FIELD_SIZE = BigInt(
|
|
8
8
|
"21888242871839275222246405745257275088548364400416034343698204186575808495617"
|
|
9
9
|
);
|
|
10
|
-
var DEFAULT_GAS_LIMIT =
|
|
10
|
+
var DEFAULT_GAS_LIMIT = 3000000n;
|
|
11
11
|
var DEFAULT_BATCH_SIZE = 10;
|
|
12
12
|
var PROOF_EXPIRY_MS = 3e5;
|
|
13
13
|
var CONTRACT_ADDRESSES = {
|
|
@@ -605,6 +605,71 @@ var PrivacyVaultSDK = class {
|
|
|
605
605
|
timestamp: Date.now()
|
|
606
606
|
};
|
|
607
607
|
}
|
|
608
|
+
async withdrawViaTEE(note, recipient, teeEndpoint = "/api/tee-withdraw") {
|
|
609
|
+
if (!this.signer) {
|
|
610
|
+
throw new Error("Signer required for withdrawals");
|
|
611
|
+
}
|
|
612
|
+
const root = await this.getLatestRoot();
|
|
613
|
+
const merklePath = this._merkleTree.generateProof(note.leafIndex);
|
|
614
|
+
const response = await fetch(teeEndpoint, {
|
|
615
|
+
method: "POST",
|
|
616
|
+
headers: { "Content-Type": "application/json" },
|
|
617
|
+
body: JSON.stringify({
|
|
618
|
+
commitment: Array.from(note.commitment),
|
|
619
|
+
nullifierSeed: Array.from(note.nullifierSeed),
|
|
620
|
+
secret: Array.from(note.secret),
|
|
621
|
+
amount: note.amount.toString(),
|
|
622
|
+
leafIndex: note.leafIndex,
|
|
623
|
+
recipient,
|
|
624
|
+
merklePath: merklePath.path.map((p) => Array.from(p)),
|
|
625
|
+
pathIndices: merklePath.indices,
|
|
626
|
+
merkleRoot: Array.from(root)
|
|
627
|
+
})
|
|
628
|
+
});
|
|
629
|
+
if (!response.ok) {
|
|
630
|
+
const error = await response.json();
|
|
631
|
+
throw new Error(error.error || "TEE withdrawal failed");
|
|
632
|
+
}
|
|
633
|
+
const result = await response.json();
|
|
634
|
+
if (!result.success) {
|
|
635
|
+
throw new Error(result.error || "TEE withdrawal failed");
|
|
636
|
+
}
|
|
637
|
+
const tx = await this.vault.withdraw(
|
|
638
|
+
result.nullifierHash,
|
|
639
|
+
bytesToHex(root),
|
|
640
|
+
recipient,
|
|
641
|
+
note.amount,
|
|
642
|
+
hexToBytes(result.zkProof),
|
|
643
|
+
this.serializeTEEAttestation(result.teeAttestation),
|
|
644
|
+
{ gasLimit: DEFAULT_GAS_LIMIT }
|
|
645
|
+
);
|
|
646
|
+
const receipt = await tx.wait();
|
|
647
|
+
return {
|
|
648
|
+
success: true,
|
|
649
|
+
txHash: receipt.hash,
|
|
650
|
+
zkProof: hexToBytes(result.zkProof),
|
|
651
|
+
nullifierHash: hexToBytes(result.nullifierHash),
|
|
652
|
+
merkleRoot: root,
|
|
653
|
+
timestamp: Date.now()
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
serializeTEEAttestation(attestation) {
|
|
657
|
+
const enclaveId = hexToBytes(attestation.enclaveId);
|
|
658
|
+
const dataHash = hexToBytes(attestation.dataHash);
|
|
659
|
+
const signature = hexToBytes(attestation.signature);
|
|
660
|
+
const timestampBytes = new Uint8Array(8);
|
|
661
|
+
new DataView(timestampBytes.buffer).setBigUint64(
|
|
662
|
+
0,
|
|
663
|
+
BigInt(attestation.timestamp),
|
|
664
|
+
false
|
|
665
|
+
);
|
|
666
|
+
return new Uint8Array([
|
|
667
|
+
...enclaveId,
|
|
668
|
+
...timestampBytes,
|
|
669
|
+
...dataHash,
|
|
670
|
+
...signature
|
|
671
|
+
]);
|
|
672
|
+
}
|
|
608
673
|
async getLatestRoot() {
|
|
609
674
|
const root = await this.readVault.getLatestRoot();
|
|
610
675
|
return hexToBytes(root);
|