@frontiercompute/zcash-ika 0.1.0 → 0.2.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 +67 -85
- package/dist/hybrid.d.ts +119 -0
- package/dist/hybrid.js +148 -0
- package/dist/index.d.ts +83 -60
- package/dist/index.js +456 -81
- package/package.json +11 -3
- 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,42 @@
|
|
|
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 type Chain = "zcash-
|
|
17
|
+
export type Chain = "zcash-transparent" | "bitcoin" | "ethereum";
|
|
17
18
|
export interface ZcashIkaConfig {
|
|
18
19
|
/** Ika network: mainnet or testnet */
|
|
19
20
|
network: "mainnet" | "testnet";
|
|
20
|
-
/** Sui RPC URL (defaults to
|
|
21
|
+
/** Sui RPC URL (defaults to PublicNode) */
|
|
21
22
|
suiRpcUrl?: string;
|
|
23
|
+
/** Sui private key (base64 encoded, suiprivkey1...) */
|
|
24
|
+
suiPrivateKey: string;
|
|
25
|
+
/** IKA coin object ID (required for Ika transactions, separate from SUI gas) */
|
|
26
|
+
ikaCoinId?: string;
|
|
22
27
|
/** Zebra node RPC for broadcasting Zcash txs */
|
|
23
|
-
zebraRpcUrl
|
|
28
|
+
zebraRpcUrl?: string;
|
|
24
29
|
/** ZAP1 API for attestation */
|
|
25
|
-
zap1ApiUrl
|
|
30
|
+
zap1ApiUrl?: string;
|
|
26
31
|
/** ZAP1 API key for write operations */
|
|
27
32
|
zap1ApiKey?: string;
|
|
28
33
|
}
|
|
29
|
-
/** Parameters for dWallet creation per chain
|
|
34
|
+
/** Parameters for dWallet creation per chain.
|
|
35
|
+
*
|
|
36
|
+
* All chains use secp256k1 - one dWallet signs for all of them.
|
|
37
|
+
* Zcash shielded (Orchard) requires RedPallas on the Pallas curve,
|
|
38
|
+
* which is not available in Ika's current MPC. Transparent ZEC works. */
|
|
30
39
|
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
40
|
readonly "zcash-transparent": {
|
|
38
41
|
readonly curve: "SECP256K1";
|
|
39
42
|
readonly algorithm: "ECDSASecp256k1";
|
|
@@ -46,11 +49,30 @@ export declare const CHAIN_PARAMS: {
|
|
|
46
49
|
readonly hash: "DoubleSHA256";
|
|
47
50
|
readonly description: "Bitcoin (secp256k1/ECDSA, DoubleSHA256)";
|
|
48
51
|
};
|
|
52
|
+
readonly ethereum: {
|
|
53
|
+
readonly curve: "SECP256K1";
|
|
54
|
+
readonly algorithm: "ECDSASecp256k1";
|
|
55
|
+
readonly hash: "KECCAK256";
|
|
56
|
+
readonly description: "Ethereum/EVM (secp256k1/ECDSA, KECCAK256)";
|
|
57
|
+
};
|
|
49
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* Derive a Zcash transparent address from a compressed secp256k1 public key.
|
|
61
|
+
*
|
|
62
|
+
* Same as Bitcoin P2PKH but with Zcash 2-byte version prefix:
|
|
63
|
+
* mainnet 0x1cb8 (t1...), testnet 0x1d25 (tm...)
|
|
64
|
+
*
|
|
65
|
+
* Steps:
|
|
66
|
+
* 1. SHA256(pubkey) then RIPEMD160 = 20-byte hash
|
|
67
|
+
* 2. Prepend 2-byte version
|
|
68
|
+
* 3. Double-SHA256 checksum (first 4 bytes)
|
|
69
|
+
* 4. Base58 encode (version + hash + checksum)
|
|
70
|
+
*/
|
|
71
|
+
export declare function deriveZcashAddress(publicKey: Uint8Array, network?: "mainnet" | "testnet"): string;
|
|
50
72
|
export interface DWalletHandle {
|
|
51
73
|
/** dWallet object ID on Sui */
|
|
52
74
|
id: string;
|
|
53
|
-
/** Raw public key bytes */
|
|
75
|
+
/** Raw public key bytes (compressed secp256k1) */
|
|
54
76
|
publicKey: Uint8Array;
|
|
55
77
|
/** Which chain this wallet targets */
|
|
56
78
|
chain: Chain;
|
|
@@ -58,14 +80,14 @@ export interface DWalletHandle {
|
|
|
58
80
|
address: string;
|
|
59
81
|
/** Ika network (mainnet/testnet) */
|
|
60
82
|
network: string;
|
|
83
|
+
/** Encryption seed (hex) - save this for signing */
|
|
84
|
+
encryptionSeed: string;
|
|
61
85
|
}
|
|
62
86
|
export interface DualCustody {
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
/** Operator ID (shared across both wallets) */
|
|
68
|
-
operatorId: string;
|
|
87
|
+
/** Zcash transparent + Bitcoin wallet (secp256k1 dWallet) */
|
|
88
|
+
primary: DWalletHandle;
|
|
89
|
+
/** Operator Sui address */
|
|
90
|
+
operatorAddress: string;
|
|
69
91
|
}
|
|
70
92
|
export interface SpendPolicy {
|
|
71
93
|
/** Max zatoshis (or satoshis) per single transaction */
|
|
@@ -78,7 +100,7 @@ export interface SpendPolicy {
|
|
|
78
100
|
approvalThreshold: number;
|
|
79
101
|
}
|
|
80
102
|
export interface SpendRequest {
|
|
81
|
-
/** Recipient address (
|
|
103
|
+
/** Recipient address (t-addr, BTC address, or ETH address) */
|
|
82
104
|
to: string;
|
|
83
105
|
/** Amount in smallest unit (zatoshis or satoshis) */
|
|
84
106
|
amount: number;
|
|
@@ -100,72 +122,73 @@ export interface SignRequest {
|
|
|
100
122
|
messageHash: Uint8Array;
|
|
101
123
|
/** Which dWallet to sign with */
|
|
102
124
|
walletId: string;
|
|
103
|
-
/** Chain determines signing params */
|
|
125
|
+
/** Chain determines signing params (hash algo) */
|
|
104
126
|
chain: Chain;
|
|
127
|
+
/** Encryption seed (hex) from wallet creation */
|
|
128
|
+
encryptionSeed: string;
|
|
129
|
+
/** dWalletCap ID (ownership proof on Sui) */
|
|
130
|
+
dWalletCapId?: string;
|
|
105
131
|
}
|
|
106
132
|
export interface SignResult {
|
|
107
|
-
/** DER-encoded
|
|
133
|
+
/** DER-encoded ECDSA signature */
|
|
108
134
|
signature: Uint8Array;
|
|
109
135
|
/** Public key used */
|
|
110
136
|
publicKey: Uint8Array;
|
|
137
|
+
/** Sui transaction digest for the sign request */
|
|
138
|
+
signTxDigest: string;
|
|
111
139
|
}
|
|
112
140
|
/**
|
|
113
|
-
* Create a
|
|
114
|
-
*
|
|
141
|
+
* Create a split-key custody wallet.
|
|
142
|
+
* One secp256k1 dWallet signs for Zcash transparent, Bitcoin, and EVM.
|
|
115
143
|
*
|
|
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
|
|
144
|
+
* Returns the dWallet handle with ID, public key, and encryption seed.
|
|
145
|
+
* Save the encryption seed - you need it for signing.
|
|
121
146
|
*/
|
|
122
|
-
export declare function createDualCustody(config: ZcashIkaConfig,
|
|
147
|
+
export declare function createDualCustody(config: ZcashIkaConfig, _operatorSeed?: Uint8Array): Promise<DualCustody>;
|
|
123
148
|
/**
|
|
124
|
-
* Create a single dWallet
|
|
149
|
+
* Create a single secp256k1 dWallet on Ika.
|
|
150
|
+
*
|
|
151
|
+
* Flow:
|
|
152
|
+
* 1. Generate encryption keys from random seed
|
|
153
|
+
* 2. Prepare DKG locally (WASM crypto)
|
|
154
|
+
* 3. Submit DKG request to Ika network
|
|
155
|
+
* 4. Poll until dWallet reaches Active state
|
|
156
|
+
* 5. Extract compressed public key
|
|
125
157
|
*/
|
|
126
|
-
export declare function createWallet(config: ZcashIkaConfig, chain: Chain,
|
|
158
|
+
export declare function createWallet(config: ZcashIkaConfig, chain: Chain, _operatorSeed?: Uint8Array): Promise<DWalletHandle>;
|
|
127
159
|
/**
|
|
128
160
|
* Sign a message hash through Ika 2PC-MPC.
|
|
129
161
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
162
|
+
* Two on-chain transactions:
|
|
163
|
+
* 1. Request presign (pre-compute MPC ephemeral key share)
|
|
164
|
+
* 2. Approve message + request signature
|
|
132
165
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* 2. Compute partial user signature locally
|
|
136
|
-
* 3. Submit to Ika coordinator
|
|
137
|
-
* 4. Poll for completion
|
|
138
|
-
* 5. Extract full signature from sign output
|
|
166
|
+
* The operator provides their encryption seed, Ika provides the network share.
|
|
167
|
+
* Neither party ever sees the full private key.
|
|
139
168
|
*/
|
|
140
|
-
export declare function sign(config: ZcashIkaConfig,
|
|
169
|
+
export declare function sign(config: ZcashIkaConfig, request: SignRequest): Promise<SignResult>;
|
|
141
170
|
/**
|
|
142
171
|
* Set spending policy on the dWallet.
|
|
143
172
|
* Policy enforced at Sui Move contract level.
|
|
144
173
|
* The agent cannot bypass it - the contract holds the DWalletCap.
|
|
145
174
|
*/
|
|
146
|
-
export declare function setPolicy(
|
|
175
|
+
export declare function setPolicy(_config: ZcashIkaConfig, _walletId: string, _policy: SpendPolicy): Promise<string>;
|
|
147
176
|
/**
|
|
148
|
-
* Spend from a
|
|
177
|
+
* Spend from a Zcash transparent wallet.
|
|
149
178
|
*
|
|
150
|
-
* 1. Build Zcash
|
|
151
|
-
* 2.
|
|
152
|
-
* 3. Sign via Ika 2PC-MPC (
|
|
179
|
+
* 1. Build Zcash transparent transaction (requires Zebra)
|
|
180
|
+
* 2. Compute sighash (DoubleSHA256)
|
|
181
|
+
* 3. Sign via Ika 2PC-MPC (secp256k1/ECDSA)
|
|
153
182
|
* 4. Attach signature to transaction
|
|
154
183
|
* 5. Broadcast via Zebra sendrawtransaction
|
|
155
184
|
* 6. Attest via ZAP1 as AGENT_ACTION
|
|
156
185
|
*/
|
|
157
|
-
export declare function
|
|
186
|
+
export declare function spendTransparent(config: ZcashIkaConfig, walletId: string, encryptionSeed: string, request: SpendRequest): Promise<SpendResult>;
|
|
158
187
|
/**
|
|
159
188
|
* 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
|
|
189
|
+
* Same MPC flow as Zcash transparent - DoubleSHA256 sighash, ECDSA signature.
|
|
167
190
|
*/
|
|
168
|
-
export declare function spendBitcoin(config: ZcashIkaConfig, walletId: string,
|
|
191
|
+
export declare function spendBitcoin(config: ZcashIkaConfig, walletId: string, encryptionSeed: string, request: SpendRequest): Promise<SpendResult>;
|
|
169
192
|
/**
|
|
170
193
|
* Verify the wallet's attestation history via ZAP1.
|
|
171
194
|
* Works today against the live API.
|