@suit-protocol/sdk 0.3.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/README.md +196 -0
- package/dist/compliance.d.ts +4 -0
- package/dist/compliance.d.ts.map +1 -0
- package/dist/compliance.js +92 -0
- package/dist/compliance.js.map +1 -0
- package/dist/crypto.d.ts +21 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +102 -0
- package/dist/crypto.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/pool.d.ts +20 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +277 -0
- package/dist/pool.js.map +1 -0
- package/dist/proofs.d.ts +8 -0
- package/dist/proofs.d.ts.map +1 -0
- package/dist/proofs.js +19 -0
- package/dist/proofs.js.map +1 -0
- package/dist/relayer.d.ts +4 -0
- package/dist/relayer.d.ts.map +1 -0
- package/dist/relayer.js +33 -0
- package/dist/relayer.js.map +1 -0
- package/dist/signer.d.ts +8 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signer.js +20 -0
- package/dist/signer.js.map +1 -0
- package/dist/sync.d.ts +18 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +76 -0
- package/dist/sync.js.map +1 -0
- package/dist/tree.d.ts +5 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +56 -0
- package/dist/tree.js.map +1 -0
- package/dist/types.d.ts +132 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/viewing-key.d.ts +6 -0
- package/dist/viewing-key.d.ts.map +1 -0
- package/dist/viewing-key.js +140 -0
- package/dist/viewing-key.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# @suit-protocol/sdk
|
|
2
|
+
|
|
3
|
+
**Pluggable ZK payment privacy for Stellar.**
|
|
4
|
+
|
|
5
|
+
The SUIT SDK is the protocol layer underneath the [SUIT app](https://suit-app.vercel.app):
|
|
6
|
+
a wallet-agnostic, storage-agnostic TypeScript library for shielding value into an
|
|
7
|
+
on-chain UTXO pool, withdrawing any portion unlinkably with a Groth16 proof, and —
|
|
8
|
+
when *you* choose — proving exactly what you did to an auditor.
|
|
9
|
+
|
|
10
|
+
Same circuit, same contracts, same proofs as the app. Drop it into any Stellar
|
|
11
|
+
project: a wallet, a payroll tool, a treasury dashboard, a CLI.
|
|
12
|
+
|
|
13
|
+
> **Private by default. Auditable by choice.**
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @suit-protocol/sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Peer requirements: the Transaction circuit artifacts (`Transaction.wasm`,
|
|
24
|
+
`Transaction_final.zkey`) must be reachable at runtime — in the browser, serve them
|
|
25
|
+
as static files; in Node, pass filesystem paths.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { SuitPool, KeypairSigner } from '@suit-protocol/sdk';
|
|
33
|
+
|
|
34
|
+
const pool = new SuitPool({
|
|
35
|
+
network: 'testnet',
|
|
36
|
+
poolId: 'CDGGJTTWSOGHKO6GCZTZQUIO4U2Y5PUQOSAWESGUUC74QUXDHGIPPX6X',
|
|
37
|
+
tokenId: 'CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC',
|
|
38
|
+
verifierId:'CDEZRSL6WXBEJZ45WVFDI6DIHJEZ6UEWY3CUJIQPLCQIVUMLXXVKON2T',
|
|
39
|
+
startLedger: 3239820,
|
|
40
|
+
signer: new KeypairSigner(process.env.SECRET_KEY!),
|
|
41
|
+
noteStore: myNoteStore, // see "Interfaces" below
|
|
42
|
+
circuitWasmPath: '/circuit-tx/Transaction.wasm',
|
|
43
|
+
circuitZkeyPath: '/circuit-tx/Transaction_final.zkey',
|
|
44
|
+
relayerUrl: '/api/relay', // optional — falls back to self-submit
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Deposit any amount into the shielded pool
|
|
48
|
+
const { note } = await pool.shield('100.5', step => console.log(step));
|
|
49
|
+
|
|
50
|
+
// Withdraw any portion to any address — unlinkable to the deposit
|
|
51
|
+
const { changeNote } = await pool.withdraw(note, '40', recipientAddress);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Two functions cover the whole payment flow. Everything else — Merkle sync, proof
|
|
55
|
+
generation, nullifier derivation, recipient binding, relayer fallback — is internal.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Interfaces
|
|
60
|
+
|
|
61
|
+
The SDK never hardcodes a wallet or a database. You plug in three small adapters.
|
|
62
|
+
|
|
63
|
+
### `Signer` — wallet-agnostic
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
interface Signer {
|
|
67
|
+
getAddress(): Promise<string>;
|
|
68
|
+
signTransaction(preparedXdr: string, networkPassphrase: string): Promise<string>;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Ships with `KeypairSigner` (raw secret key, for scripts/servers). The app implements
|
|
73
|
+
a `FreighterSigner` over `@stellar/freighter-api`. Implement your own for Albedo,
|
|
74
|
+
Ledger, WalletConnect, a backend HSM — anything that can sign a Stellar tx.
|
|
75
|
+
|
|
76
|
+
### `NoteStore` — storage-agnostic
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
interface NoteStore {
|
|
80
|
+
getNotes(poolId: string): UTXONote[];
|
|
81
|
+
saveNotes(poolId: string, notes: UTXONote[]): void;
|
|
82
|
+
getViewingSeed(poolId: string): string | null;
|
|
83
|
+
setViewingSeed(poolId: string, seed: string): void;
|
|
84
|
+
getAuditLog(poolId: string): EncryptedAuditEntry[];
|
|
85
|
+
appendAuditEntry(poolId: string, entry: EncryptedAuditEntry): void;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Secret note material and the encrypted audit log live here. The app uses
|
|
90
|
+
`localStorage`; a server might use Postgres, a wallet might use IndexedDB or the
|
|
91
|
+
device keystore. Notes are the only secrets — the Merkle tree is reconstructed from
|
|
92
|
+
chain events, so a `NoteStore` never has to be authoritative about pool state.
|
|
93
|
+
|
|
94
|
+
### `LeafCache` — optional tree persistence
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
interface LeafCache {
|
|
98
|
+
load(poolId: string): Map<number, string>;
|
|
99
|
+
save(poolId: string, data: Map<number, string>): void;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Persists reconstructed leaves so the tree survives past the RPC's event-retention
|
|
104
|
+
window. Optional — omit it and the SDK syncs from `startLedger` each session.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Auditable by choice
|
|
109
|
+
|
|
110
|
+
Privacy that can't be disclosed is a liability for anyone who has to answer to a
|
|
111
|
+
regulator. SUIT separates *spending* from *seeing*.
|
|
112
|
+
|
|
113
|
+
### Viewing keys
|
|
114
|
+
|
|
115
|
+
A viewing key is a symmetric key that decrypts your audit log. Hand it to an auditor
|
|
116
|
+
with an exported package and they can recompute `Poseidon(amount, pubKey, blinding)`
|
|
117
|
+
for every note and check it against the on-chain commitment — they see **every amount
|
|
118
|
+
you shielded and withdrew**, but they hold no private key, so they can **never spend**.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { getViewingKeyHex, exportAuditPackage, verifyAuditPackage } from '@suit-protocol/sdk';
|
|
122
|
+
|
|
123
|
+
const viewingKey = getViewingKeyHex(noteStore, poolId); // share out-of-band
|
|
124
|
+
const pkg = exportAuditPackage(pool.config); // hand to the auditor
|
|
125
|
+
|
|
126
|
+
// Auditor side (static — needs only the package + key + an RPC URL):
|
|
127
|
+
const report = await verifyAuditPackage(pkg, viewingKey);
|
|
128
|
+
// → { valid, totalShielded, totalWithdrawn, netBalance, entries: [{ ..., onChainVerified }] }
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Compliance receipts
|
|
132
|
+
|
|
133
|
+
A receipt is a voluntary, point-in-time proof that links **one** withdrawal back to
|
|
134
|
+
**one** deposit — for a tax filing or a specific inquiry, without exposing the rest of
|
|
135
|
+
your activity.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { generateReceipt, verifyReceipt } from '@suit-protocol/sdk';
|
|
139
|
+
|
|
140
|
+
const receipt = generateReceipt(
|
|
141
|
+
poolId, 'testnet', spentNote,
|
|
142
|
+
withdrawAmountStroops, recipient, withdrawTxHash, changeNote,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// Anyone can verify against chain state:
|
|
146
|
+
const v = await verifyReceipt(receipt);
|
|
147
|
+
// → { valid, commitmentValid, commitmentOnChain, nullifierBurned }
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`commitmentValid` re-derives the Poseidon commitment from the disclosed amount;
|
|
151
|
+
`commitmentOnChain` confirms that deposit actually entered the pool.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Architecture
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
@suit-protocol/sdk
|
|
159
|
+
├── pool.ts SuitPool — shield() / withdraw() / getRoot() / getCount()
|
|
160
|
+
├── crypto.ts field arithmetic, Poseidon wrappers, extDataHash binding
|
|
161
|
+
├── tree.ts depth-16 Poseidon Merkle tree (root, path, zeros)
|
|
162
|
+
├── sync.ts LeafSyncer — rebuilds the tree from `transact` events
|
|
163
|
+
├── proofs.ts dummy inputs + Groth16 point encoding for the verifier
|
|
164
|
+
├── relayer.ts non-custodial relayer client (GET info, POST bundle)
|
|
165
|
+
├── signer.ts Signer interface + KeypairSigner
|
|
166
|
+
├── viewing-key.ts AES-GCM audit log, export/verify (Web Crypto, zero-dep)
|
|
167
|
+
├── compliance.ts receipt generation + on-chain verification
|
|
168
|
+
└── types.ts all interfaces and data types
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Every byte of the proof path — Poseidon constants, commitment layout, the
|
|
172
|
+
`keccak256(recipient‖relayer‖fee)` recipient binding — matches the on-chain
|
|
173
|
+
`pool_v3` contract exactly. The chain only ever sees roots, nullifiers, and
|
|
174
|
+
commitments; never amounts or the link between a deposit and a withdrawal.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## API reference
|
|
179
|
+
|
|
180
|
+
| Method | Description |
|
|
181
|
+
|---|---|
|
|
182
|
+
| `new SuitPool(config)` | Construct a pool client for one asset deployment. |
|
|
183
|
+
| `pool.shield(amount, onStep?)` | Deposit any amount; returns `{ txHash, note }`. |
|
|
184
|
+
| `pool.withdraw(note, amount, recipient, onStep?)` | Withdraw any portion; returns `{ txHash, changeNote }`. |
|
|
185
|
+
| `pool.getRoot()` / `pool.getCount()` | Current on-chain Merkle root / leaf count. |
|
|
186
|
+
| `pool.getNotes()` | Local notes for this pool from the `NoteStore`. |
|
|
187
|
+
| `pool.syncLeaves(force?)` | Rebuild the leaf set from chain events. |
|
|
188
|
+
| `pool.getRelayerInfo()` | Relayer pubkey + fee, or `null` if offline. |
|
|
189
|
+
| `getViewingKeyHex` / `exportAuditPackage` / `verifyAuditPackage` | Viewing-key disclosure flow. |
|
|
190
|
+
| `generateReceipt` / `verifyReceipt` | Compliance receipt flow. |
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
MIT.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ComplianceReceipt, ReceiptVerification, UTXONote } from './types';
|
|
2
|
+
export declare function generateReceipt(poolId: string, network: string, note: UTXONote, withdrawAmountStroops: string, recipient: string, withdrawTxHash: string, changeNote?: UTXONote | null, decimals?: number): ComplianceReceipt;
|
|
3
|
+
export declare function verifyReceipt(receipt: ComplianceReceipt, rpcUrl?: string): Promise<ReceiptVerification>;
|
|
4
|
+
//# sourceMappingURL=compliance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compliance.d.ts","sourceRoot":"","sources":["../src/compliance.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGhF,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,QAAQ,EACd,qBAAqB,EAAE,MAAM,EAC7B,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,UAAU,CAAC,EAAE,QAAQ,GAAG,IAAI,EAC5B,QAAQ,SAAI,GACX,iBAAiB,CA+BnB;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,iBAAiB,EAC1B,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,mBAAmB,CAAC,CAuD9B"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SUIT Protocol SDK — Compliance receipts
|
|
3
|
+
//
|
|
4
|
+
// A compliance receipt is a voluntary disclosure that links a specific
|
|
5
|
+
// withdrawal back to a specific deposit. The user generates one when they
|
|
6
|
+
// need to (tax reporting, regulatory inquiry). Anyone with the receipt can
|
|
7
|
+
// cryptographically verify it against on-chain state.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.generateReceipt = generateReceipt;
|
|
10
|
+
exports.verifyReceipt = verifyReceipt;
|
|
11
|
+
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
12
|
+
const crypto_1 = require("./crypto");
|
|
13
|
+
function generateReceipt(poolId, network, note, withdrawAmountStroops, recipient, withdrawTxHash, changeNote, decimals = 7) {
|
|
14
|
+
const pk = (0, crypto_1.pubKeyOf)(BigInt(note.privKey));
|
|
15
|
+
const receipt = {
|
|
16
|
+
version: 1,
|
|
17
|
+
poolId,
|
|
18
|
+
network,
|
|
19
|
+
deposit: {
|
|
20
|
+
amount: (0, crypto_1.stroopsToAmount)(note.amount, decimals),
|
|
21
|
+
pubKey: pk.toString(),
|
|
22
|
+
blinding: note.blinding,
|
|
23
|
+
commitment: note.commitment,
|
|
24
|
+
txHash: note.txHash,
|
|
25
|
+
timestamp: note.ts,
|
|
26
|
+
},
|
|
27
|
+
withdrawal: {
|
|
28
|
+
amount: (0, crypto_1.stroopsToAmount)(withdrawAmountStroops, decimals),
|
|
29
|
+
recipient,
|
|
30
|
+
txHash: withdrawTxHash,
|
|
31
|
+
timestamp: Date.now(),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
if (changeNote) {
|
|
35
|
+
receipt.change = {
|
|
36
|
+
amount: (0, crypto_1.stroopsToAmount)(changeNote.amount, decimals),
|
|
37
|
+
commitment: changeNote.commitment,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return receipt;
|
|
41
|
+
}
|
|
42
|
+
async function verifyReceipt(receipt, rpcUrl) {
|
|
43
|
+
const pk = BigInt(receipt.deposit.pubKey);
|
|
44
|
+
const bl = BigInt(receipt.deposit.blinding);
|
|
45
|
+
// Re-parse the human-readable amount back to stroops to recompute the commitment.
|
|
46
|
+
// stroopsToAmount produces "X.Y" from stroops; we reverse it here.
|
|
47
|
+
const amtParts = receipt.deposit.amount.split('.');
|
|
48
|
+
const whole = BigInt(amtParts[0] || '0');
|
|
49
|
+
const fracStr = (amtParts[1] || '').padEnd(7, '0').slice(0, 7);
|
|
50
|
+
const amt = whole * 10000000n + BigInt(fracStr);
|
|
51
|
+
const recomputed = (0, crypto_1.commitHash)(amt, pk, bl).toString();
|
|
52
|
+
const commitmentValid = recomputed === receipt.deposit.commitment;
|
|
53
|
+
const url = rpcUrl ??
|
|
54
|
+
(receipt.network === 'mainnet' ? 'https://mainnet.sorobanrpc.com' : 'https://soroban-testnet.stellar.org');
|
|
55
|
+
let commitmentOnChain = false;
|
|
56
|
+
let nullifierBurned = false;
|
|
57
|
+
try {
|
|
58
|
+
const server = new stellar_sdk_1.rpc.Server(url);
|
|
59
|
+
const latest = (await server.getLatestLedger()).sequence;
|
|
60
|
+
const start = Math.max(latest - 16000, 1);
|
|
61
|
+
const filters = [{ type: 'contract', contractIds: [receipt.poolId], topics: [['*']] }];
|
|
62
|
+
const checkEvents = (events) => {
|
|
63
|
+
for (const e of events) {
|
|
64
|
+
try {
|
|
65
|
+
const data = (0, stellar_sdk_1.scValToNative)(e.value);
|
|
66
|
+
if (data?.out_commitment_0) {
|
|
67
|
+
const c0 = (0, crypto_1.bytesToBig)(data.out_commitment_0).toString();
|
|
68
|
+
const c1 = (0, crypto_1.bytesToBig)(data.out_commitment_1).toString();
|
|
69
|
+
if (c0 === receipt.deposit.commitment || c1 === receipt.deposit.commitment) {
|
|
70
|
+
commitmentOnChain = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch { /* skip */ }
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
let res = await server.getEvents({ startLedger: start, filters, limit: 200 });
|
|
78
|
+
checkEvents(res.events);
|
|
79
|
+
while (res.events.length === 200 && res.cursor) {
|
|
80
|
+
res = await server.getEvents({ filters, limit: 200, cursor: res.cursor });
|
|
81
|
+
checkEvents(res.events);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch { /* network error */ }
|
|
85
|
+
return {
|
|
86
|
+
valid: commitmentValid && commitmentOnChain,
|
|
87
|
+
commitmentValid,
|
|
88
|
+
commitmentOnChain,
|
|
89
|
+
nullifierBurned,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=compliance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compliance.js","sourceRoot":"","sources":["../src/compliance.ts"],"names":[],"mappings":";AAAA,0CAA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,MAAM,EAAS,CAAC,CAAC;YAC1F,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAC;IAE/B,OAAO;QACL,KAAK,EAAE,eAAe,IAAI,iBAAiB;QAC3C,eAAe;QACf,iBAAiB;QACjB,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { poseidon2 } from 'poseidon-lite';
|
|
2
|
+
import { xdr } from '@stellar/stellar-sdk';
|
|
3
|
+
export declare const P = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
4
|
+
export declare const DEFAULT_DECIMALS = 7;
|
|
5
|
+
export declare function randomField(): bigint;
|
|
6
|
+
export declare function be(v: bigint, n?: number): Uint8Array;
|
|
7
|
+
export declare function beRaw(v: bigint, n?: number): Uint8Array;
|
|
8
|
+
export declare function bytesToBig(b: Uint8Array | number[] | Buffer): bigint;
|
|
9
|
+
export declare function concatBytes(arrs: Uint8Array[]): Uint8Array;
|
|
10
|
+
export declare const toHex: (b: Uint8Array) => string;
|
|
11
|
+
export declare const fromHex: (h: string) => Uint8Array<ArrayBuffer>;
|
|
12
|
+
export declare const pubKeyOf: (priv: bigint) => bigint;
|
|
13
|
+
export declare const commitHash: (amount: bigint, pk: bigint, blinding: bigint) => bigint;
|
|
14
|
+
export declare const signHash: (priv: bigint, commitment: bigint, idx: bigint) => bigint;
|
|
15
|
+
export declare const nullHash: (commitment: bigint, idx: bigint, sig: bigint) => bigint;
|
|
16
|
+
export { poseidon2 };
|
|
17
|
+
export declare function amountToStroops(amount: string, decimals?: number): bigint;
|
|
18
|
+
export declare function stroopsToAmount(stroops: bigint | string, decimals?: number): string;
|
|
19
|
+
export declare function extDataHashField(recipient: string, relayer: string, fee: bigint): bigint;
|
|
20
|
+
export declare const scvBytes: (b: Uint8Array) => xdr.ScVal;
|
|
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M,CAMnF;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,SAAmB,GAAG,MAAM,CAO7F;AAID,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAMxF;AAID,eAAO,MAAM,QAAQ,GAAI,GAAG,UAAU,cAAuC,CAAC"}
|
package/dist/crypto.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SUIT Protocol SDK — Field arithmetic, Poseidon wrappers, byte helpers
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.scvBytes = exports.poseidon2 = exports.nullHash = exports.signHash = exports.commitHash = exports.pubKeyOf = exports.fromHex = exports.toHex = exports.DEFAULT_DECIMALS = exports.P = void 0;
|
|
5
|
+
exports.randomField = randomField;
|
|
6
|
+
exports.be = be;
|
|
7
|
+
exports.beRaw = beRaw;
|
|
8
|
+
exports.bytesToBig = bytesToBig;
|
|
9
|
+
exports.concatBytes = concatBytes;
|
|
10
|
+
exports.amountToStroops = amountToStroops;
|
|
11
|
+
exports.stroopsToAmount = stroopsToAmount;
|
|
12
|
+
exports.extDataHashField = extDataHashField;
|
|
13
|
+
const poseidon_lite_1 = require("poseidon-lite");
|
|
14
|
+
Object.defineProperty(exports, "poseidon2", { enumerable: true, get: function () { return poseidon_lite_1.poseidon2; } });
|
|
15
|
+
const js_sha3_1 = require("js-sha3");
|
|
16
|
+
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
17
|
+
exports.P = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
18
|
+
exports.DEFAULT_DECIMALS = 7;
|
|
19
|
+
function randomField() {
|
|
20
|
+
const b = new Uint8Array(31);
|
|
21
|
+
crypto.getRandomValues(b);
|
|
22
|
+
let v = 0n;
|
|
23
|
+
for (const x of b)
|
|
24
|
+
v = (v << 8n) | BigInt(x);
|
|
25
|
+
return v % exports.P;
|
|
26
|
+
}
|
|
27
|
+
function be(v, n = 32) {
|
|
28
|
+
let x = ((v % exports.P) + exports.P) % exports.P;
|
|
29
|
+
const o = new Uint8Array(n);
|
|
30
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
31
|
+
o[i] = Number(x & 0xffn);
|
|
32
|
+
x >>= 8n;
|
|
33
|
+
}
|
|
34
|
+
return o;
|
|
35
|
+
}
|
|
36
|
+
function beRaw(v, n = 32) {
|
|
37
|
+
let x = v;
|
|
38
|
+
const o = new Uint8Array(n);
|
|
39
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
40
|
+
o[i] = Number(x & 0xffn);
|
|
41
|
+
x >>= 8n;
|
|
42
|
+
}
|
|
43
|
+
return o;
|
|
44
|
+
}
|
|
45
|
+
function bytesToBig(b) {
|
|
46
|
+
let v = 0n;
|
|
47
|
+
for (const x of b)
|
|
48
|
+
v = (v << 8n) | BigInt(x);
|
|
49
|
+
return v;
|
|
50
|
+
}
|
|
51
|
+
function concatBytes(arrs) {
|
|
52
|
+
const len = arrs.reduce((s, x) => s + x.length, 0);
|
|
53
|
+
const o = new Uint8Array(len);
|
|
54
|
+
let p = 0;
|
|
55
|
+
for (const x of arrs) {
|
|
56
|
+
o.set(x, p);
|
|
57
|
+
p += x.length;
|
|
58
|
+
}
|
|
59
|
+
return o;
|
|
60
|
+
}
|
|
61
|
+
const toHex = (b) => Array.from(b).map(x => x.toString(16).padStart(2, '0')).join('');
|
|
62
|
+
exports.toHex = toHex;
|
|
63
|
+
const fromHex = (h) => new Uint8Array((h.match(/.{1,2}/g) || []).map(x => parseInt(x, 16)));
|
|
64
|
+
exports.fromHex = fromHex;
|
|
65
|
+
// ── Poseidon (BN254, matches circomlib exactly) ──
|
|
66
|
+
const pubKeyOf = (priv) => (0, poseidon_lite_1.poseidon1)([priv]);
|
|
67
|
+
exports.pubKeyOf = pubKeyOf;
|
|
68
|
+
const commitHash = (amount, pk, blinding) => (0, poseidon_lite_1.poseidon3)([amount, pk, blinding]);
|
|
69
|
+
exports.commitHash = commitHash;
|
|
70
|
+
const signHash = (priv, commitment, idx) => (0, poseidon_lite_1.poseidon3)([priv, commitment, idx]);
|
|
71
|
+
exports.signHash = signHash;
|
|
72
|
+
const nullHash = (commitment, idx, sig) => (0, poseidon_lite_1.poseidon3)([commitment, idx, sig]);
|
|
73
|
+
exports.nullHash = nullHash;
|
|
74
|
+
// ── Amount conversion ──
|
|
75
|
+
function amountToStroops(amount, decimals = exports.DEFAULT_DECIMALS) {
|
|
76
|
+
const unit = 10n ** BigInt(decimals);
|
|
77
|
+
const parts = amount.split('.');
|
|
78
|
+
const whole = BigInt(parts[0] || '0');
|
|
79
|
+
const frac = (parts[1] || '').padEnd(decimals, '0').slice(0, decimals);
|
|
80
|
+
return whole * unit + BigInt(frac);
|
|
81
|
+
}
|
|
82
|
+
function stroopsToAmount(stroops, decimals = exports.DEFAULT_DECIMALS) {
|
|
83
|
+
const s = BigInt(stroops);
|
|
84
|
+
const unit = 10n ** BigInt(decimals);
|
|
85
|
+
const whole = s / unit;
|
|
86
|
+
const frac = s % unit;
|
|
87
|
+
if (frac === 0n)
|
|
88
|
+
return whole.toString();
|
|
89
|
+
return `${whole}.${frac.toString().padStart(decimals, '0').replace(/0+$/, '')}`;
|
|
90
|
+
}
|
|
91
|
+
// ── extDataHash — binds (recipient, relayer, fee) into the proof ──
|
|
92
|
+
function extDataHashField(recipient, relayer, fee) {
|
|
93
|
+
const rb = new Uint8Array(new stellar_sdk_1.Address(recipient).toScVal().toXDR());
|
|
94
|
+
const lb = new Uint8Array(new stellar_sdk_1.Address(relayer).toScVal().toXDR());
|
|
95
|
+
const fb = beRaw(fee, 16);
|
|
96
|
+
const d = new Uint8Array(js_sha3_1.keccak256.arrayBuffer(concatBytes([rb, lb, fb])));
|
|
97
|
+
return bytesToBig(d.slice(1));
|
|
98
|
+
}
|
|
99
|
+
// ── Soroban helpers ──
|
|
100
|
+
const scvBytes = (b) => stellar_sdk_1.xdr.ScVal.scvBytes(Buffer.from(b));
|
|
101
|
+
exports.scvBytes = scvBytes;
|
|
102
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;AASxE,kCAMC;AAED,gBAKC;AAED,sBAKC;AAED,gCAIC;AAED,kCAMC;AAsBD,0CAMC;AAED,0CAOC;AAID,4CAMC;AAxFD,iDAAgE;AA2DvD,0FA3DW,yBAAS,OA2DX;AA1DlB,qCAAoC;AACpC,sDAAoD;AAEvC,QAAA,CAAC,GAAG,8EAA8E,CAAC;AACnF,QAAA,gBAAgB,GAAG,CAAC,CAAC;AAElC,SAAgB,WAAW;IACzB,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC7B,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,CAAC,GAAG,EAAE,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,CAAC;QAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,SAAC,CAAC;AACf,CAAC;AAED,SAAgB,EAAE,CAAC,CAAS,EAAE,CAAC,GAAG,EAAE;IAClC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAC,CAAC,GAAG,SAAC,CAAC,GAAG,SAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QAAC,CAA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AAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;IAClE,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC1B,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,mBAAS,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,OAAO,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,wBAAwB;AAEjB,MAAM,QAAQ,GAAG,CAAC,CAAa,EAAE,EAAE,CAAC,iBAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAAjE,QAAA,QAAQ,YAAyD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { SuitPool } from './pool';
|
|
2
|
+
export { KeypairSigner } from './signer';
|
|
3
|
+
export { LeafSyncer } from './sync';
|
|
4
|
+
export type { SyncConfig } from './sync';
|
|
5
|
+
export { randomField, pubKeyOf, commitHash, signHash, nullHash, amountToStroops, stroopsToAmount, extDataHashField, be, beRaw, bytesToBig, concatBytes, toHex, fromHex, scvBytes, P, DEFAULT_DECIMALS, } from './crypto';
|
|
6
|
+
export { computeZeros, treeRoot, treePath, emptyPath } from './tree';
|
|
7
|
+
export { dummyInput, encodeProof } from './proofs';
|
|
8
|
+
export { getRelayerInfo, relaySubmit } from './relayer';
|
|
9
|
+
export { appendAuditLog, getViewingKeyHex, exportAuditPackage, verifyAuditPackage, } from './viewing-key';
|
|
10
|
+
export { generateReceipt, verifyReceipt } from './compliance';
|
|
11
|
+
export type { SuitPoolConfig, Signer, NoteStore, LeafCache, UTXONote, ShieldResult, WithdrawResult, RelayerInfo, RelayBundle, EncryptedAuditEntry, AuditEntry, AuditPackage, AuditReport, ComplianceReceipt, ReceiptVerification, } from './types';
|
|
12
|
+
export declare const VERSION = "0.3.0";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,YAAY,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,EACL,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EACrD,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAClD,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAC5D,CAAC,EAAE,gBAAgB,GACpB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExD,OAAO,EACL,cAAc,EAAE,gBAAgB,EAChC,kBAAkB,EAAE,kBAAkB,GACvC,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE9D,YAAY,EACV,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAC5C,QAAQ,EAAE,YAAY,EAAE,cAAc,EACtC,WAAW,EAAE,WAAW,EACxB,mBAAmB,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAC1D,iBAAiB,EAAE,mBAAmB,GACvC,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SUIT Protocol SDK — public API surface
|
|
3
|
+
// Private by default. Auditable by choice.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.VERSION = exports.verifyReceipt = exports.generateReceipt = exports.verifyAuditPackage = exports.exportAuditPackage = exports.getViewingKeyHex = exports.appendAuditLog = exports.relaySubmit = exports.getRelayerInfo = exports.encodeProof = exports.dummyInput = exports.emptyPath = exports.treePath = exports.treeRoot = exports.computeZeros = exports.DEFAULT_DECIMALS = exports.P = exports.scvBytes = exports.fromHex = exports.toHex = exports.concatBytes = exports.bytesToBig = exports.beRaw = exports.be = exports.extDataHashField = exports.stroopsToAmount = exports.amountToStroops = exports.nullHash = exports.signHash = exports.commitHash = exports.pubKeyOf = exports.randomField = exports.LeafSyncer = exports.KeypairSigner = exports.SuitPool = void 0;
|
|
6
|
+
var pool_1 = require("./pool");
|
|
7
|
+
Object.defineProperty(exports, "SuitPool", { enumerable: true, get: function () { return pool_1.SuitPool; } });
|
|
8
|
+
var signer_1 = require("./signer");
|
|
9
|
+
Object.defineProperty(exports, "KeypairSigner", { enumerable: true, get: function () { return signer_1.KeypairSigner; } });
|
|
10
|
+
var sync_1 = require("./sync");
|
|
11
|
+
Object.defineProperty(exports, "LeafSyncer", { enumerable: true, get: function () { return sync_1.LeafSyncer; } });
|
|
12
|
+
var crypto_1 = require("./crypto");
|
|
13
|
+
Object.defineProperty(exports, "randomField", { enumerable: true, get: function () { return crypto_1.randomField; } });
|
|
14
|
+
Object.defineProperty(exports, "pubKeyOf", { enumerable: true, get: function () { return crypto_1.pubKeyOf; } });
|
|
15
|
+
Object.defineProperty(exports, "commitHash", { enumerable: true, get: function () { return crypto_1.commitHash; } });
|
|
16
|
+
Object.defineProperty(exports, "signHash", { enumerable: true, get: function () { return crypto_1.signHash; } });
|
|
17
|
+
Object.defineProperty(exports, "nullHash", { enumerable: true, get: function () { return crypto_1.nullHash; } });
|
|
18
|
+
Object.defineProperty(exports, "amountToStroops", { enumerable: true, get: function () { return crypto_1.amountToStroops; } });
|
|
19
|
+
Object.defineProperty(exports, "stroopsToAmount", { enumerable: true, get: function () { return crypto_1.stroopsToAmount; } });
|
|
20
|
+
Object.defineProperty(exports, "extDataHashField", { enumerable: true, get: function () { return crypto_1.extDataHashField; } });
|
|
21
|
+
Object.defineProperty(exports, "be", { enumerable: true, get: function () { return crypto_1.be; } });
|
|
22
|
+
Object.defineProperty(exports, "beRaw", { enumerable: true, get: function () { return crypto_1.beRaw; } });
|
|
23
|
+
Object.defineProperty(exports, "bytesToBig", { enumerable: true, get: function () { return crypto_1.bytesToBig; } });
|
|
24
|
+
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function () { return crypto_1.concatBytes; } });
|
|
25
|
+
Object.defineProperty(exports, "toHex", { enumerable: true, get: function () { return crypto_1.toHex; } });
|
|
26
|
+
Object.defineProperty(exports, "fromHex", { enumerable: true, get: function () { return crypto_1.fromHex; } });
|
|
27
|
+
Object.defineProperty(exports, "scvBytes", { enumerable: true, get: function () { return crypto_1.scvBytes; } });
|
|
28
|
+
Object.defineProperty(exports, "P", { enumerable: true, get: function () { return crypto_1.P; } });
|
|
29
|
+
Object.defineProperty(exports, "DEFAULT_DECIMALS", { enumerable: true, get: function () { return crypto_1.DEFAULT_DECIMALS; } });
|
|
30
|
+
var tree_1 = require("./tree");
|
|
31
|
+
Object.defineProperty(exports, "computeZeros", { enumerable: true, get: function () { return tree_1.computeZeros; } });
|
|
32
|
+
Object.defineProperty(exports, "treeRoot", { enumerable: true, get: function () { return tree_1.treeRoot; } });
|
|
33
|
+
Object.defineProperty(exports, "treePath", { enumerable: true, get: function () { return tree_1.treePath; } });
|
|
34
|
+
Object.defineProperty(exports, "emptyPath", { enumerable: true, get: function () { return tree_1.emptyPath; } });
|
|
35
|
+
var proofs_1 = require("./proofs");
|
|
36
|
+
Object.defineProperty(exports, "dummyInput", { enumerable: true, get: function () { return proofs_1.dummyInput; } });
|
|
37
|
+
Object.defineProperty(exports, "encodeProof", { enumerable: true, get: function () { return proofs_1.encodeProof; } });
|
|
38
|
+
var relayer_1 = require("./relayer");
|
|
39
|
+
Object.defineProperty(exports, "getRelayerInfo", { enumerable: true, get: function () { return relayer_1.getRelayerInfo; } });
|
|
40
|
+
Object.defineProperty(exports, "relaySubmit", { enumerable: true, get: function () { return relayer_1.relaySubmit; } });
|
|
41
|
+
var viewing_key_1 = require("./viewing-key");
|
|
42
|
+
Object.defineProperty(exports, "appendAuditLog", { enumerable: true, get: function () { return viewing_key_1.appendAuditLog; } });
|
|
43
|
+
Object.defineProperty(exports, "getViewingKeyHex", { enumerable: true, get: function () { return viewing_key_1.getViewingKeyHex; } });
|
|
44
|
+
Object.defineProperty(exports, "exportAuditPackage", { enumerable: true, get: function () { return viewing_key_1.exportAuditPackage; } });
|
|
45
|
+
Object.defineProperty(exports, "verifyAuditPackage", { enumerable: true, get: function () { return viewing_key_1.verifyAuditPackage; } });
|
|
46
|
+
var compliance_1 = require("./compliance");
|
|
47
|
+
Object.defineProperty(exports, "generateReceipt", { enumerable: true, get: function () { return compliance_1.generateReceipt; } });
|
|
48
|
+
Object.defineProperty(exports, "verifyReceipt", { enumerable: true, get: function () { return compliance_1.verifyReceipt; } });
|
|
49
|
+
exports.VERSION = '0.3.0';
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,2CAA2C;;;AAE3C,+BAAkC;AAAzB,gGAAA,QAAQ,OAAA;AACjB,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AACtB,+BAAoC;AAA3B,kGAAA,UAAU,OAAA;AAGnB,mCAKkB;AAJhB,qGAAA,WAAW,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAAE,oGAAA,UAAU,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAAE,kGAAA,QAAQ,OAAA;AACrD,yGAAA,eAAe,OAAA;AAAE,yGAAA,eAAe,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAClD,4FAAA,EAAE,OAAA;AAAE,+FAAA,KAAK,OAAA;AAAE,oGAAA,UAAU,OAAA;AAAE,qGAAA,WAAW,OAAA;AAAE,+FAAA,KAAK,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAC5D,2FAAA,CAAC,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAGrB,+BAAqE;AAA5D,oGAAA,YAAY,OAAA;AAAE,gGAAA,QAAQ,OAAA;AAAE,gGAAA,QAAQ,OAAA;AAAE,iGAAA,SAAS,OAAA;AACpD,mCAAmD;AAA1C,oGAAA,UAAU,OAAA;AAAE,qGAAA,WAAW,OAAA;AAChC,qCAAwD;AAA/C,yGAAA,cAAc,OAAA;AAAE,sGAAA,WAAW,OAAA;AAEpC,6CAGuB;AAFrB,6GAAA,cAAc,OAAA;AAAE,+GAAA,gBAAgB,OAAA;AAChC,iHAAA,kBAAkB,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AAGxC,2CAA8D;AAArD,6GAAA,eAAe,OAAA;AAAE,2GAAA,aAAa,OAAA;AAU1B,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
package/dist/pool.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SuitPoolConfig, UTXONote, ShieldResult, WithdrawResult } from './types';
|
|
2
|
+
export declare class SuitPool {
|
|
3
|
+
readonly config: SuitPoolConfig;
|
|
4
|
+
private server;
|
|
5
|
+
private passphrase;
|
|
6
|
+
private syncer;
|
|
7
|
+
private depth;
|
|
8
|
+
private decimals;
|
|
9
|
+
constructor(config: SuitPoolConfig);
|
|
10
|
+
getRoot(): Promise<bigint>;
|
|
11
|
+
getCount(): Promise<number>;
|
|
12
|
+
getRelayerInfo(): Promise<import("./types").RelayerInfo | null>;
|
|
13
|
+
syncLeaves(force?: boolean): Promise<bigint[]>;
|
|
14
|
+
getNotes(): UTXONote[];
|
|
15
|
+
shield(amount: string, onStep?: (m: string) => void): Promise<ShieldResult>;
|
|
16
|
+
withdraw(note: UTXONote, amount: string, recipient: string, onStep?: (m: string) => void): Promise<WithdrawResult>;
|
|
17
|
+
private callView;
|
|
18
|
+
private signAndSend;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,cAAc,EAAqB,QAAQ,EAC3C,YAAY,EAAE,cAAc,EAC7B,MAAM,SAAS,CAAC;AAYjB,qBAAa,QAAQ;IACnB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAS;gBAEb,MAAM,EAAE,cAAc;IAkB5B,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAK1B,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3B,cAAc;IAKd,UAAU,CAAC,KAAK,UAAQ;IAI9B,QAAQ,IAAI,QAAQ,EAAE;IAMhB,MAAM,CACV,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAC3B,OAAO,CAAC,YAAY,CAAC;IA2ElB,QAAQ,CACZ,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GAC3B,OAAO,CAAC,cAAc,CAAC;YA2HZ,QAAQ;YAWR,WAAW;CAgC1B"}
|