@frontiercompute/zcash-ika 0.1.0 → 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 +126 -92
- package/dist/hybrid.d.ts +119 -0
- package/dist/hybrid.js +148 -0
- package/dist/index.d.ts +117 -65
- package/dist/index.js +671 -88
- package/dist/tx-builder.d.ts +67 -0
- package/dist/tx-builder.js +534 -0
- package/package.json +32 -4
- package/dist/test-dkg.d.ts +0 -17
- package/dist/test-dkg.js +0 -150
- package/src/index.ts +0 -338
- package/src/test-dkg.ts +0 -199
- package/tsconfig.json +0 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,39 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @frontiercompute/zcash-ika
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Split-key custody for Zcash transparent, Bitcoin, and EVM chains.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - secp256k1 dWallet -> Bitcoin (BTC) + Zcash transparent (t-addr)
|
|
9
|
-
*
|
|
10
|
-
* Neither key ever exists whole. Both chains signed through Ika 2PC-MPC.
|
|
6
|
+
* One secp256k1 dWallet signs for all three chain families.
|
|
7
|
+
* Neither key half can sign alone. Policy enforced by Sui Move contract.
|
|
11
8
|
* Every operation attested to Zcash via ZAP1.
|
|
12
9
|
*
|
|
13
10
|
* Built on Ika's 2PC-MPC network (Sui).
|
|
11
|
+
*
|
|
12
|
+
* NOTE: Zcash shielded (Orchard) uses RedPallas on the Pallas curve,
|
|
13
|
+
* which Ika does not currently support. Only transparent ZEC (secp256k1)
|
|
14
|
+
* is viable through this package today.
|
|
14
15
|
*/
|
|
15
16
|
export { Curve, Hash, SignatureAlgorithm, IkaClient, IkaTransaction, UserShareEncryptionKeys, getNetworkConfig, createClassGroupsKeypair, createRandomSessionIdentifier, prepareDKG, prepareDKGAsync, prepareDKGSecondRound, prepareDKGSecondRoundAsync, createDKGUserOutput, publicKeyFromDWalletOutput, parseSignatureFromSignOutput, } from "@ika.xyz/sdk";
|
|
16
|
-
export
|
|
17
|
+
export { fetchUTXOs, selectUTXOs, buildUnsignedTx, attachSignatures, broadcastTx, estimateFee, BRANCH_ID, } from "./tx-builder.js";
|
|
18
|
+
export type { UTXO } from "./tx-builder.js";
|
|
19
|
+
export type Chain = "zcash-transparent" | "bitcoin" | "ethereum";
|
|
17
20
|
export interface ZcashIkaConfig {
|
|
18
21
|
/** Ika network: mainnet or testnet */
|
|
19
22
|
network: "mainnet" | "testnet";
|
|
20
|
-
/** Sui RPC URL (defaults to
|
|
23
|
+
/** Sui RPC URL (defaults to PublicNode) */
|
|
21
24
|
suiRpcUrl?: string;
|
|
25
|
+
/** Sui private key (base64 encoded, suiprivkey1...) */
|
|
26
|
+
suiPrivateKey: string;
|
|
27
|
+
/** IKA coin object ID (required for Ika transactions, separate from SUI gas) */
|
|
28
|
+
ikaCoinId?: string;
|
|
22
29
|
/** Zebra node RPC for broadcasting Zcash txs */
|
|
23
|
-
zebraRpcUrl
|
|
30
|
+
zebraRpcUrl?: string;
|
|
24
31
|
/** ZAP1 API for attestation */
|
|
25
|
-
zap1ApiUrl
|
|
32
|
+
zap1ApiUrl?: string;
|
|
26
33
|
/** ZAP1 API key for write operations */
|
|
27
34
|
zap1ApiKey?: string;
|
|
28
35
|
}
|
|
29
|
-
/** Parameters for dWallet creation per chain
|
|
36
|
+
/** Parameters for dWallet creation per chain.
|
|
37
|
+
*
|
|
38
|
+
* All chains use secp256k1 - one dWallet signs for all of them.
|
|
39
|
+
* Zcash shielded (Orchard) requires RedPallas on the Pallas curve,
|
|
40
|
+
* which is not available in Ika's current MPC. Transparent ZEC works. */
|
|
30
41
|
export declare const CHAIN_PARAMS: {
|
|
31
|
-
readonly "zcash-shielded": {
|
|
32
|
-
readonly curve: "ED25519";
|
|
33
|
-
readonly algorithm: "EdDSA";
|
|
34
|
-
readonly hash: "SHA512";
|
|
35
|
-
readonly description: "Zcash Orchard shielded pool (Ed25519/EdDSA)";
|
|
36
|
-
};
|
|
37
42
|
readonly "zcash-transparent": {
|
|
38
43
|
readonly curve: "SECP256K1";
|
|
39
44
|
readonly algorithm: "ECDSASecp256k1";
|
|
@@ -46,11 +51,30 @@ export declare const CHAIN_PARAMS: {
|
|
|
46
51
|
readonly hash: "DoubleSHA256";
|
|
47
52
|
readonly description: "Bitcoin (secp256k1/ECDSA, DoubleSHA256)";
|
|
48
53
|
};
|
|
54
|
+
readonly ethereum: {
|
|
55
|
+
readonly curve: "SECP256K1";
|
|
56
|
+
readonly algorithm: "ECDSASecp256k1";
|
|
57
|
+
readonly hash: "KECCAK256";
|
|
58
|
+
readonly description: "Ethereum/EVM (secp256k1/ECDSA, KECCAK256)";
|
|
59
|
+
};
|
|
49
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Derive a Zcash transparent address from a compressed secp256k1 public key.
|
|
63
|
+
*
|
|
64
|
+
* Same as Bitcoin P2PKH but with Zcash 2-byte version prefix:
|
|
65
|
+
* mainnet 0x1cb8 (t1...), testnet 0x1d25 (tm...)
|
|
66
|
+
*
|
|
67
|
+
* Steps:
|
|
68
|
+
* 1. SHA256(pubkey) then RIPEMD160 = 20-byte hash
|
|
69
|
+
* 2. Prepend 2-byte version
|
|
70
|
+
* 3. Double-SHA256 checksum (first 4 bytes)
|
|
71
|
+
* 4. Base58 encode (version + hash + checksum)
|
|
72
|
+
*/
|
|
73
|
+
export declare function deriveZcashAddress(publicKey: Uint8Array, network?: "mainnet" | "testnet"): string;
|
|
50
74
|
export interface DWalletHandle {
|
|
51
75
|
/** dWallet object ID on Sui */
|
|
52
76
|
id: string;
|
|
53
|
-
/** Raw public key bytes */
|
|
77
|
+
/** Raw public key bytes (compressed secp256k1) */
|
|
54
78
|
publicKey: Uint8Array;
|
|
55
79
|
/** Which chain this wallet targets */
|
|
56
80
|
chain: Chain;
|
|
@@ -58,14 +82,14 @@ export interface DWalletHandle {
|
|
|
58
82
|
address: string;
|
|
59
83
|
/** Ika network (mainnet/testnet) */
|
|
60
84
|
network: string;
|
|
85
|
+
/** Encryption seed (hex) - save this for signing */
|
|
86
|
+
encryptionSeed: string;
|
|
61
87
|
}
|
|
62
88
|
export interface DualCustody {
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
/** Operator ID (shared across both wallets) */
|
|
68
|
-
operatorId: string;
|
|
89
|
+
/** Zcash transparent + Bitcoin wallet (secp256k1 dWallet) */
|
|
90
|
+
primary: DWalletHandle;
|
|
91
|
+
/** Operator Sui address */
|
|
92
|
+
operatorAddress: string;
|
|
69
93
|
}
|
|
70
94
|
export interface SpendPolicy {
|
|
71
95
|
/** Max zatoshis (or satoshis) per single transaction */
|
|
@@ -78,7 +102,7 @@ export interface SpendPolicy {
|
|
|
78
102
|
approvalThreshold: number;
|
|
79
103
|
}
|
|
80
104
|
export interface SpendRequest {
|
|
81
|
-
/** Recipient address (
|
|
105
|
+
/** Recipient address (t-addr, BTC address, or ETH address) */
|
|
82
106
|
to: string;
|
|
83
107
|
/** Amount in smallest unit (zatoshis or satoshis) */
|
|
84
108
|
amount: number;
|
|
@@ -100,72 +124,100 @@ export interface SignRequest {
|
|
|
100
124
|
messageHash: Uint8Array;
|
|
101
125
|
/** Which dWallet to sign with */
|
|
102
126
|
walletId: string;
|
|
103
|
-
/** Chain determines signing params */
|
|
127
|
+
/** Chain determines signing params (hash algo) */
|
|
104
128
|
chain: Chain;
|
|
129
|
+
/** Encryption seed (hex) from wallet creation */
|
|
130
|
+
encryptionSeed: string;
|
|
131
|
+
/** dWalletCap ID (ownership proof on Sui) */
|
|
132
|
+
dWalletCapId?: string;
|
|
105
133
|
}
|
|
106
134
|
export interface SignResult {
|
|
107
|
-
/** DER-encoded
|
|
135
|
+
/** DER-encoded ECDSA signature */
|
|
108
136
|
signature: Uint8Array;
|
|
109
137
|
/** Public key used */
|
|
110
138
|
publicKey: Uint8Array;
|
|
139
|
+
/** Sui transaction digest for the sign request */
|
|
140
|
+
signTxDigest: string;
|
|
111
141
|
}
|
|
112
142
|
/**
|
|
113
|
-
* Create a
|
|
114
|
-
*
|
|
143
|
+
* Create a split-key custody wallet.
|
|
144
|
+
* One secp256k1 dWallet signs for Zcash transparent, Bitcoin, and EVM.
|
|
115
145
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* 2. Run DKG on Ika (2PC-MPC key generation)
|
|
119
|
-
* 3. Extract public key, derive chain-specific address
|
|
120
|
-
* 4. Attest wallet creation via ZAP1
|
|
146
|
+
* Returns the dWallet handle with ID, public key, and encryption seed.
|
|
147
|
+
* Save the encryption seed - you need it for signing.
|
|
121
148
|
*/
|
|
122
|
-
export declare function createDualCustody(config: ZcashIkaConfig,
|
|
149
|
+
export declare function createDualCustody(config: ZcashIkaConfig, _operatorSeed?: Uint8Array): Promise<DualCustody>;
|
|
123
150
|
/**
|
|
124
|
-
* Create a single dWallet
|
|
151
|
+
* Create a single secp256k1 dWallet on Ika.
|
|
152
|
+
*
|
|
153
|
+
* Flow:
|
|
154
|
+
* 1. Generate encryption keys from random seed
|
|
155
|
+
* 2. Prepare DKG locally (WASM crypto)
|
|
156
|
+
* 3. Submit DKG request to Ika network
|
|
157
|
+
* 4. Poll until dWallet reaches Active state
|
|
158
|
+
* 5. Extract compressed public key
|
|
125
159
|
*/
|
|
126
|
-
export declare function createWallet(config: ZcashIkaConfig, chain: Chain,
|
|
160
|
+
export declare function createWallet(config: ZcashIkaConfig, chain: Chain, _operatorSeed?: Uint8Array): Promise<DWalletHandle>;
|
|
127
161
|
/**
|
|
128
162
|
* Sign a message hash through Ika 2PC-MPC.
|
|
129
163
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
164
|
+
* Two on-chain transactions:
|
|
165
|
+
* 1. Request presign (pre-compute MPC ephemeral key share)
|
|
166
|
+
* 2. Approve message + request signature
|
|
132
167
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
168
|
+
* The operator provides their encryption seed, Ika provides the network share.
|
|
169
|
+
* Neither party ever sees the full private key.
|
|
170
|
+
*/
|
|
171
|
+
export declare function sign(config: ZcashIkaConfig, request: SignRequest): Promise<SignResult>;
|
|
172
|
+
export interface PolicyResult {
|
|
173
|
+
/** SpendPolicy shared object ID on Sui */
|
|
174
|
+
policyId: string;
|
|
175
|
+
/** PolicyCap object ID (owner holds this to manage policy) */
|
|
176
|
+
capId: string;
|
|
177
|
+
/** Sui transaction digest */
|
|
178
|
+
txDigest: string;
|
|
179
|
+
}
|
|
180
|
+
export interface PolicyState {
|
|
181
|
+
policyId: string;
|
|
182
|
+
dwalletId: string;
|
|
183
|
+
owner: string;
|
|
184
|
+
maxPerTx: number;
|
|
185
|
+
maxDaily: number;
|
|
186
|
+
dailySpent: number;
|
|
187
|
+
windowStart: number;
|
|
188
|
+
allowedRecipients: string[];
|
|
189
|
+
frozen: boolean;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Set spending policy on a dWallet.
|
|
193
|
+
* Creates a SpendPolicy shared object and PolicyCap on Sui.
|
|
194
|
+
* The PolicyCap is transferred to the caller.
|
|
139
195
|
*/
|
|
140
|
-
export declare function
|
|
196
|
+
export declare function setPolicy(config: ZcashIkaConfig, walletId: string, policy: SpendPolicy): Promise<PolicyResult>;
|
|
141
197
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* The agent cannot bypass it - the contract holds the DWalletCap.
|
|
198
|
+
* Query a SpendPolicy object and check if a spend would be allowed.
|
|
199
|
+
* Returns the full policy state plus a boolean for the specific check.
|
|
145
200
|
*/
|
|
146
|
-
export declare function
|
|
201
|
+
export declare function checkPolicy(config: ZcashIkaConfig, policyId: string, amount?: number, recipient?: string): Promise<PolicyState & {
|
|
202
|
+
allowed: boolean;
|
|
203
|
+
}>;
|
|
147
204
|
/**
|
|
148
|
-
* Spend from a
|
|
205
|
+
* Spend from a Zcash transparent wallet.
|
|
149
206
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
207
|
+
* Full pipeline:
|
|
208
|
+
* 1. Fetch UTXOs from Zebra
|
|
209
|
+
* 2. Build unsigned TX, compute ZIP 244 sighashes
|
|
210
|
+
* 3. Sign each sighash via Ika 2PC-MPC
|
|
211
|
+
* 4. Attach signatures, serialize signed TX
|
|
154
212
|
* 5. Broadcast via Zebra sendrawtransaction
|
|
155
|
-
* 6. Attest
|
|
213
|
+
* 6. Attest to ZAP1 as AGENT_ACTION
|
|
156
214
|
*/
|
|
157
|
-
export declare function
|
|
215
|
+
export declare function spendTransparent(config: ZcashIkaConfig, walletId: string, encryptionSeed: string, request: SpendRequest): Promise<SpendResult>;
|
|
158
216
|
/**
|
|
159
217
|
* Spend from a Bitcoin wallet.
|
|
160
|
-
*
|
|
161
|
-
* 1. Build Bitcoin transaction
|
|
162
|
-
* 2. Compute sighash (DoubleSHA256)
|
|
163
|
-
* 3. Sign via Ika 2PC-MPC (secp256k1/ECDSA)
|
|
164
|
-
* 4. Attach signature
|
|
165
|
-
* 5. Broadcast to Bitcoin network
|
|
166
|
-
* 6. Attest via ZAP1 as AGENT_ACTION
|
|
218
|
+
* Same MPC flow as Zcash transparent - DoubleSHA256 sighash, ECDSA signature.
|
|
167
219
|
*/
|
|
168
|
-
export declare function spendBitcoin(config: ZcashIkaConfig, walletId: string,
|
|
220
|
+
export declare function spendBitcoin(config: ZcashIkaConfig, walletId: string, encryptionSeed: string, request: SpendRequest): Promise<SpendResult>;
|
|
169
221
|
/**
|
|
170
222
|
* Verify the wallet's attestation history via ZAP1.
|
|
171
223
|
* Works today against the live API.
|