@tatumio/wallet-sdk 0.0.2 → 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 +3 -1
- package/dist/chains.d.ts +1 -1
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +13 -13
- package/dist/chains.js.map +1 -1
- package/dist/constants/paths.d.ts +4 -2
- package/dist/constants/paths.d.ts.map +1 -1
- package/dist/constants/paths.js +4 -2
- package/dist/constants/paths.js.map +1 -1
- package/dist/constants/urls.d.ts +1 -1
- package/dist/constants/urls.js +1 -1
- package/dist/eject/birkhoff.d.ts +7 -0
- package/dist/eject/birkhoff.d.ts.map +1 -0
- package/dist/eject/birkhoff.js +33 -0
- package/dist/eject/birkhoff.js.map +1 -0
- package/dist/eject/curves.d.ts +24 -0
- package/dist/eject/curves.d.ts.map +1 -0
- package/dist/eject/curves.js +85 -0
- package/dist/eject/curves.js.map +1 -0
- package/dist/eject/index.d.ts +4 -0
- package/dist/eject/index.d.ts.map +1 -0
- package/dist/eject/index.js +2 -0
- package/dist/eject/index.js.map +1 -0
- package/dist/eject/matrix.d.ts +17 -0
- package/dist/eject/matrix.d.ts.map +1 -0
- package/dist/eject/matrix.js +110 -0
- package/dist/eject/matrix.js.map +1 -0
- package/dist/eject/reconstruct.d.ts +16 -0
- package/dist/eject/reconstruct.d.ts.map +1 -0
- package/dist/eject/reconstruct.js +48 -0
- package/dist/eject/reconstruct.js.map +1 -0
- package/dist/eject/shares.d.ts +34 -0
- package/dist/eject/shares.d.ts.map +1 -0
- package/dist/eject/shares.js +67 -0
- package/dist/eject/shares.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/portal/custodian.d.ts +38 -21
- package/dist/portal/custodian.d.ts.map +1 -1
- package/dist/portal/custodian.js +57 -27
- package/dist/portal/custodian.js.map +1 -1
- package/dist/portal/enclave-api.d.ts.map +1 -1
- package/dist/portal/enclave-api.js +16 -8
- package/dist/portal/enclave-api.js.map +1 -1
- package/dist/portal/types/custodian.d.ts +24 -0
- package/dist/portal/types/custodian.d.ts.map +1 -1
- package/dist/portal/wallets-client.d.ts +8 -0
- package/dist/portal/wallets-client.d.ts.map +1 -1
- package/dist/portal/wallets-client.js +10 -0
- package/dist/portal/wallets-client.js.map +1 -1
- package/dist/sdk.js +1 -1
- package/dist/sdk.js.map +1 -1
- package/dist/tatum/provider.d.ts +12 -3
- package/dist/tatum/provider.d.ts.map +1 -1
- package/dist/tatum/provider.js +22 -17
- package/dist/tatum/provider.js.map +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@ const wallets = new TatumWalletsSdk({
|
|
|
21
21
|
|
|
22
22
|
For lower-level or not-yet-modeled Tatum calls, use `wallets.api.request(...)` directly.
|
|
23
23
|
|
|
24
|
+
See [docs/USAGE.md](docs/USAGE.md) for the full guide and complete API reference.
|
|
25
|
+
|
|
24
26
|
## Custodian and Client Operations
|
|
25
27
|
|
|
26
28
|
Custodian-scoped calls are authenticated through your Tatum API key:
|
|
@@ -154,7 +156,7 @@ const recovered = await client.recoverWallet({
|
|
|
154
156
|
}); // typed as RecoverWalletResponse
|
|
155
157
|
```
|
|
156
158
|
|
|
157
|
-
Custodian-scoped calls are authenticated
|
|
159
|
+
Custodian-scoped calls are authenticated with your Tatum `x-api-key` — that single key is all you ever pass. Enclave operations that need an RPC URL get one automatically — the SDK builds `https://<network>.gateway.tatum.io/<your-api-key>` from the chain's `tatumNetwork` (see `WALLET_CHAINS`) — unless you pass an explicit `rpcUrl` in the body.
|
|
158
160
|
|
|
159
161
|
## Development
|
|
160
162
|
|
package/dist/chains.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface WalletChainConfig {
|
|
|
29
29
|
/** Whether an explicit `rpcUrl` is required for enclave operations on this chain. */
|
|
30
30
|
requiresRpcUrl: boolean;
|
|
31
31
|
/** Tatum RPC gateway network slug (`<slug>.gateway.tatum.io`). */
|
|
32
|
-
|
|
32
|
+
tatumNetwork: string;
|
|
33
33
|
}
|
|
34
34
|
/** Per-chain configuration, keyed by {@link WalletChain}. */
|
|
35
35
|
export declare const WALLET_CHAINS: Record<WalletChain, WalletChainConfig>;
|
package/dist/chains.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEtD;;;;;;GAMG;AACH,oBAAY,WAAW;IACrB,aAAa,eAAe;IAC5B,gBAAgB,aAAa;IAC7B,gBAAgB,oBAAoB;IACpC,cAAc,4CAA4C;IAC1D,eAAe,mBAAmB;IAClC,YAAY,iBAAiB;IAC7B,eAAe,mDAAmD;IAClE,gBAAgB,iBAAiB;IACjC,iBAAiB,iBAAiB;IAClC,YAAY,gBAAgB;IAC5B,gBAAgB,cAAc;IAC9B,eAAe,eAAe;IAC9B,YAAY,iBAAiB;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,OAAO,EAAE,WAAW,CAAC;IACrB,8FAA8F;IAC9F,KAAK,EAAE,KAAK,CAAC;IACb,qFAAqF;IACrF,cAAc,EAAE,OAAO,CAAC;IACxB,kEAAkE;IAClE,
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEtD;;;;;;GAMG;AACH,oBAAY,WAAW;IACrB,aAAa,eAAe;IAC5B,gBAAgB,aAAa;IAC7B,gBAAgB,oBAAoB;IACpC,cAAc,4CAA4C;IAC1D,eAAe,mBAAmB;IAClC,YAAY,iBAAiB;IAC7B,eAAe,mDAAmD;IAClE,gBAAgB,iBAAiB;IACjC,iBAAiB,iBAAiB;IAClC,YAAY,gBAAgB;IAC5B,gBAAgB,cAAc;IAC9B,eAAe,eAAe;IAC9B,YAAY,iBAAiB;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,4EAA4E;IAC5E,OAAO,EAAE,WAAW,CAAC;IACrB,8FAA8F;IAC9F,KAAK,EAAE,KAAK,CAAC;IACb,qFAAqF;IACrF,cAAc,EAAE,OAAO,CAAC;IACxB,kEAAkE;IAClE,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,6DAA6D;AAC7D,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,iBAAiB,CA+EhE,CAAC;AAEF,uDAAuD;AACvD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,iBAAiB,CAE1E"}
|
package/dist/chains.js
CHANGED
|
@@ -27,79 +27,79 @@ export const WALLET_CHAINS = {
|
|
|
27
27
|
chainId: WalletChain.MONAD_MAINNET,
|
|
28
28
|
curve: 'SECP256K1',
|
|
29
29
|
requiresRpcUrl: false,
|
|
30
|
-
|
|
30
|
+
tatumNetwork: 'monad-mainnet'
|
|
31
31
|
},
|
|
32
32
|
[WalletChain.ETHEREUM_MAINNET]: {
|
|
33
33
|
chainId: WalletChain.ETHEREUM_MAINNET,
|
|
34
34
|
curve: 'SECP256K1',
|
|
35
35
|
requiresRpcUrl: false,
|
|
36
|
-
|
|
36
|
+
tatumNetwork: 'ethereum-mainnet'
|
|
37
37
|
},
|
|
38
38
|
[WalletChain.ETHEREUM_SEPOLIA]: {
|
|
39
39
|
chainId: WalletChain.ETHEREUM_SEPOLIA,
|
|
40
40
|
curve: 'SECP256K1',
|
|
41
41
|
requiresRpcUrl: false,
|
|
42
|
-
|
|
42
|
+
tatumNetwork: 'ethereum-sepolia'
|
|
43
43
|
},
|
|
44
44
|
[WalletChain.SOLANA_MAINNET]: {
|
|
45
45
|
chainId: WalletChain.SOLANA_MAINNET,
|
|
46
46
|
curve: 'ED25519',
|
|
47
47
|
requiresRpcUrl: false,
|
|
48
|
-
|
|
48
|
+
tatumNetwork: 'solana-mainnet'
|
|
49
49
|
},
|
|
50
50
|
[WalletChain.STELLAR_MAINNET]: {
|
|
51
51
|
chainId: WalletChain.STELLAR_MAINNET,
|
|
52
52
|
curve: 'ED25519',
|
|
53
53
|
requiresRpcUrl: true,
|
|
54
|
-
|
|
54
|
+
tatumNetwork: 'stellar-mainnet'
|
|
55
55
|
},
|
|
56
56
|
[WalletChain.TRON_MAINNET]: {
|
|
57
57
|
chainId: WalletChain.TRON_MAINNET,
|
|
58
58
|
curve: 'SECP256K1',
|
|
59
59
|
requiresRpcUrl: true,
|
|
60
|
-
|
|
60
|
+
tatumNetwork: 'tron-mainnet'
|
|
61
61
|
},
|
|
62
62
|
[WalletChain.BITCOIN_MAINNET]: {
|
|
63
63
|
chainId: WalletChain.BITCOIN_MAINNET,
|
|
64
64
|
curve: 'SECP256K1',
|
|
65
65
|
requiresRpcUrl: true,
|
|
66
|
-
|
|
66
|
+
tatumNetwork: 'bitcoin-mainnet'
|
|
67
67
|
},
|
|
68
68
|
[WalletChain.ARBITRUM_MAINNET]: {
|
|
69
69
|
chainId: WalletChain.ARBITRUM_MAINNET,
|
|
70
70
|
curve: 'SECP256K1',
|
|
71
71
|
requiresRpcUrl: false,
|
|
72
|
-
|
|
72
|
+
tatumNetwork: 'arb-one-mainnet'
|
|
73
73
|
},
|
|
74
74
|
[WalletChain.AVALANCHE_MAINNET]: {
|
|
75
75
|
chainId: WalletChain.AVALANCHE_MAINNET,
|
|
76
76
|
curve: 'SECP256K1',
|
|
77
77
|
requiresRpcUrl: false,
|
|
78
|
-
|
|
78
|
+
tatumNetwork: 'avax-mainnet'
|
|
79
79
|
},
|
|
80
80
|
[WalletChain.BASE_MAINNET]: {
|
|
81
81
|
chainId: WalletChain.BASE_MAINNET,
|
|
82
82
|
curve: 'SECP256K1',
|
|
83
83
|
requiresRpcUrl: false,
|
|
84
|
-
|
|
84
|
+
tatumNetwork: 'base-mainnet'
|
|
85
85
|
},
|
|
86
86
|
[WalletChain.OPTIMISM_MAINNET]: {
|
|
87
87
|
chainId: WalletChain.OPTIMISM_MAINNET,
|
|
88
88
|
curve: 'SECP256K1',
|
|
89
89
|
requiresRpcUrl: false,
|
|
90
|
-
|
|
90
|
+
tatumNetwork: 'optimism-mainnet'
|
|
91
91
|
},
|
|
92
92
|
[WalletChain.POLYGON_MAINNET]: {
|
|
93
93
|
chainId: WalletChain.POLYGON_MAINNET,
|
|
94
94
|
curve: 'SECP256K1',
|
|
95
95
|
requiresRpcUrl: false,
|
|
96
|
-
|
|
96
|
+
tatumNetwork: 'polygon-mainnet'
|
|
97
97
|
},
|
|
98
98
|
[WalletChain.CELO_MAINNET]: {
|
|
99
99
|
chainId: WalletChain.CELO_MAINNET,
|
|
100
100
|
curve: 'SECP256K1',
|
|
101
101
|
requiresRpcUrl: true,
|
|
102
|
-
|
|
102
|
+
tatumNetwork: 'celo-mainnet'
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
/** Resolve the configuration for a supported chain. */
|
package/dist/chains.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chains.js","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,WAcX;AAdD,WAAY,WAAW;IACrB,2CAA4B,CAAA;IAC5B,4CAA6B,CAAA;IAC7B,mDAAoC,CAAA;IACpC,yEAA0D,CAAA;IAC1D,iDAAkC,CAAA;IAClC,4CAA6B,CAAA;IAC7B,iFAAkE,CAAA;IAClE,gDAAiC,CAAA;IACjC,iDAAkC,CAAA;IAClC,2CAA4B,CAAA;IAC5B,6CAA8B,CAAA;IAC9B,6CAA8B,CAAA;IAC9B,4CAA6B,CAAA;AAC/B,CAAC,EAdW,WAAW,KAAX,WAAW,QActB;AAaD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,aAAa,GAA2C;IACnE,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE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WAAW;QAClB,cAAc,EAAE,KAAK;QACrB,YAAY,EAAE,iBAAiB;KAChC;IACD,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE;QAC1B,OAAO,EAAE,WAAW,CAAC,YAAY;QACjC,KAAK,EAAE,WAAW;QAClB,cAAc,EAAE,IAAI;QACpB,YAAY,EAAE,cAAc;KAC7B;CACF,CAAC;AAEF,uDAAuD;AACvD,MAAM,UAAU,oBAAoB,CAAC,KAAkB;IACrD,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
/** Tatum endpoint
|
|
2
|
-
export declare const
|
|
1
|
+
/** Tatum usage-metering endpoint hit once per wallet generation. */
|
|
2
|
+
export declare const USAGE_WALLET_PATH = "/v4/wallets/usage/wallet";
|
|
3
|
+
/** Tatum usage-metering endpoint hit once per signing operation (sign/rawSign/sendAssets). */
|
|
4
|
+
export declare const USAGE_TRANSACTION_PATH = "/v4/wallets/usage/transaction";
|
|
3
5
|
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/constants/paths.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/constants/paths.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,eAAO,MAAM,iBAAiB,6BAA6B,CAAC;AAE5D,8FAA8F;AAC9F,eAAO,MAAM,sBAAsB,kCAAkC,CAAC"}
|
package/dist/constants/paths.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
/** Tatum endpoint
|
|
2
|
-
export const
|
|
1
|
+
/** Tatum usage-metering endpoint hit once per wallet generation. */
|
|
2
|
+
export const USAGE_WALLET_PATH = '/v4/wallets/usage/wallet';
|
|
3
|
+
/** Tatum usage-metering endpoint hit once per signing operation (sign/rawSign/sendAssets). */
|
|
4
|
+
export const USAGE_TRANSACTION_PATH = '/v4/wallets/usage/transaction';
|
|
3
5
|
//# sourceMappingURL=paths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/constants/paths.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/constants/paths.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,MAAM,CAAC,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAE5D,8FAA8F;AAC9F,MAAM,CAAC,MAAM,sBAAsB,GAAG,+BAA+B,CAAC"}
|
package/dist/constants/urls.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const PORTAL_ENCLAVE_BASE_URL = "https://mpc-client.portalhq.io";
|
|
|
7
7
|
/**
|
|
8
8
|
* Tatum RPC gateway domain. Per-chain RPC URLs are built as
|
|
9
9
|
* `https://<network>.${TATUM_RPC_GATEWAY_DOMAIN}/<apiKey>` (the `<network>`
|
|
10
|
-
* slug comes from each chain's {@link WalletChainConfig.
|
|
10
|
+
* slug comes from each chain's {@link WalletChainConfig.tatumNetwork}).
|
|
11
11
|
*/
|
|
12
12
|
export declare const TATUM_RPC_GATEWAY_DOMAIN = "gateway.tatum.io";
|
|
13
13
|
//# sourceMappingURL=urls.d.ts.map
|
package/dist/constants/urls.js
CHANGED
|
@@ -7,7 +7,7 @@ export const PORTAL_ENCLAVE_BASE_URL = 'https://mpc-client.portalhq.io';
|
|
|
7
7
|
/**
|
|
8
8
|
* Tatum RPC gateway domain. Per-chain RPC URLs are built as
|
|
9
9
|
* `https://<network>.${TATUM_RPC_GATEWAY_DOMAIN}/<apiKey>` (the `<network>`
|
|
10
|
-
* slug comes from each chain's {@link WalletChainConfig.
|
|
10
|
+
* slug comes from each chain's {@link WalletChainConfig.tatumNetwork}).
|
|
11
11
|
*/
|
|
12
12
|
export const TATUM_RPC_GATEWAY_DOMAIN = 'gateway.tatum.io';
|
|
13
13
|
//# sourceMappingURL=urls.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface Bk {
|
|
2
|
+
x: bigint;
|
|
3
|
+
rank: number;
|
|
4
|
+
}
|
|
5
|
+
/** First row of the pseudoinverse — the interpolation weights that recover the secret. */
|
|
6
|
+
export declare function computeBkCoefficient(bks: Bk[], threshold: number, fieldOrder: bigint): bigint[];
|
|
7
|
+
//# sourceMappingURL=birkhoff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"birkhoff.d.ts","sourceRoot":"","sources":["../../src/eject/birkhoff.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,EAAE;IACjB,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;CACd;AAgCD,0FAA0F;AAC1F,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAG/F"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Matrix } from './matrix.js';
|
|
2
|
+
import { modPow } from './curves.js';
|
|
3
|
+
/** Coefficient of the differential monomial of given degree/rank evaluated at x. */
|
|
4
|
+
function getDiffMonomialCoeff(x, fieldOrder, degree, rank) {
|
|
5
|
+
if (degree < rank)
|
|
6
|
+
return 0n;
|
|
7
|
+
if (degree === 0)
|
|
8
|
+
return 1n;
|
|
9
|
+
let extra = 1n;
|
|
10
|
+
for (let j = 0; j < rank; j++)
|
|
11
|
+
extra *= BigInt(degree - j);
|
|
12
|
+
const power = BigInt(degree - rank);
|
|
13
|
+
const result = modPow(x, power, fieldOrder);
|
|
14
|
+
return (result * extra) % fieldOrder;
|
|
15
|
+
}
|
|
16
|
+
function getLinearEquationCoefficient(bkX, fieldOrder, degreePoly, rank) {
|
|
17
|
+
const result = new Array(degreePoly + 1);
|
|
18
|
+
for (let i = 0; i < result.length; i++) {
|
|
19
|
+
result[i] = getDiffMonomialCoeff(bkX, fieldOrder, i, rank);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function linearEquationCoefficientMatrix(bks, threshold, fieldOrder) {
|
|
24
|
+
const degree = threshold - 1;
|
|
25
|
+
const data = bks.map((bk) => getLinearEquationCoefficient(bk.x, fieldOrder, degree, bk.rank));
|
|
26
|
+
return new Matrix(fieldOrder, data);
|
|
27
|
+
}
|
|
28
|
+
/** First row of the pseudoinverse — the interpolation weights that recover the secret. */
|
|
29
|
+
export function computeBkCoefficient(bks, threshold, fieldOrder) {
|
|
30
|
+
const matrix = linearEquationCoefficientMatrix(bks, threshold, fieldOrder);
|
|
31
|
+
return matrix.Pseudoinverse().GetRow(0);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=birkhoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"birkhoff.js","sourceRoot":"","sources":["../../src/eject/birkhoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,oFAAoF;AACpF,SAAS,oBAAoB,CAAC,CAAS,EAAE,UAAkB,EAAE,MAAc,EAAE,IAAY;IACvF,IAAI,MAAM,GAAG,IAAI;QAAE,OAAO,EAAE,CAAC;IAC7B,IAAI,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC5B,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;QAAE,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;IAC5C,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,UAAU,CAAC;AACvC,CAAC;AAED,SAAS,4BAA4B,CACnC,GAAW,EACX,UAAkB,EAClB,UAAkB,EAClB,IAAY;IAEZ,MAAM,MAAM,GAAa,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;IACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,+BAA+B,CAAC,GAAS,EAAE,SAAiB,EAAE,UAAkB;IACvF,MAAM,MAAM,GAAG,SAAS,GAAG,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,4BAA4B,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9F,OAAO,IAAI,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,oBAAoB,CAAC,GAAS,EAAE,SAAiB,EAAE,UAAkB;IACnF,MAAM,MAAM,GAAG,+BAA+B,CAAC,GAAG,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Curve } from '../portal/types/index.js';
|
|
2
|
+
export type { Curve };
|
|
3
|
+
/** Group orders for the supported curves (the modulus for share arithmetic). */
|
|
4
|
+
export declare const FIELD_ORDER: Record<Curve, bigint>;
|
|
5
|
+
/** Always-non-negative remainder. */
|
|
6
|
+
export declare function mod(a: bigint, m: bigint): bigint;
|
|
7
|
+
/** Modular exponentiation x^n mod m. */
|
|
8
|
+
export declare function modPow(x: bigint, n: bigint, m: bigint): bigint;
|
|
9
|
+
/** Modular inverse via the extended Euclidean algorithm. Throws if none exists. */
|
|
10
|
+
export declare function modInverse(a: bigint, m: bigint): bigint;
|
|
11
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
12
|
+
/** Minimal big-endian byte representation of a non-negative bigint. */
|
|
13
|
+
export declare function bigIntToBytesBE(value: bigint): Uint8Array;
|
|
14
|
+
/** 32-byte big-endian hex string (left-padded). */
|
|
15
|
+
export declare function toPaddedHexBE(value: bigint): string;
|
|
16
|
+
/**
|
|
17
|
+
* Reverse the minimal big-endian bytes of `value` into a 32-byte buffer,
|
|
18
|
+
* right-aligned (zero-padded at the front). This matches @portal-hq/eject-js's
|
|
19
|
+
* ed25519 output exactly — including its treatment of scalars with leading
|
|
20
|
+
* zero bytes — so reconstructed keys are byte-identical to the reference.
|
|
21
|
+
* Note: this is NOT a plain left-aligned little-endian encoding.
|
|
22
|
+
*/
|
|
23
|
+
export declare function toLittleEndian32(value: bigint): Uint8Array;
|
|
24
|
+
//# sourceMappingURL=curves.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curves.d.ts","sourceRoot":"","sources":["../../src/eject/curves.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEtD,YAAY,EAAE,KAAK,EAAE,CAAC;AAEtB,gFAAgF;AAChF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAG7C,CAAC;AAEF,qCAAqC;AACrC,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wCAAwC;AACxC,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAW9D;AAED,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAYvD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CASzD;AAED,mDAAmD;AACnD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAQ1D"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Group orders for the supported curves (the modulus for share arithmetic). */
|
|
2
|
+
export const FIELD_ORDER = {
|
|
3
|
+
SECP256K1: BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'),
|
|
4
|
+
ED25519: BigInt('0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed'),
|
|
5
|
+
};
|
|
6
|
+
/** Always-non-negative remainder. */
|
|
7
|
+
export function mod(a, m) {
|
|
8
|
+
return ((a % m) + m) % m;
|
|
9
|
+
}
|
|
10
|
+
/** Modular exponentiation x^n mod m. */
|
|
11
|
+
export function modPow(x, n, m) {
|
|
12
|
+
if (m === 1n)
|
|
13
|
+
return 0n;
|
|
14
|
+
let result = 1n;
|
|
15
|
+
let base = x % m;
|
|
16
|
+
let exp = n;
|
|
17
|
+
while (exp > 0n) {
|
|
18
|
+
if (exp % 2n === 1n)
|
|
19
|
+
result = (result * base) % m;
|
|
20
|
+
exp /= 2n;
|
|
21
|
+
base = (base * base) % m;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
/** Modular inverse via the extended Euclidean algorithm. Throws if none exists. */
|
|
26
|
+
export function modInverse(a, m) {
|
|
27
|
+
const aa = mod(a, m);
|
|
28
|
+
if (aa === 0n)
|
|
29
|
+
throw new Error('Modular inverse does not exist');
|
|
30
|
+
let [oldR, r] = [aa, m];
|
|
31
|
+
let [oldS, s] = [1n, 0n];
|
|
32
|
+
while (r !== 0n) {
|
|
33
|
+
const q = oldR / r;
|
|
34
|
+
[oldR, r] = [r, oldR - q * r];
|
|
35
|
+
[oldS, s] = [s, oldS - q * s];
|
|
36
|
+
}
|
|
37
|
+
if (oldR !== 1n)
|
|
38
|
+
throw new Error('Modular inverse does not exist');
|
|
39
|
+
return mod(oldS, m);
|
|
40
|
+
}
|
|
41
|
+
export function bytesToHex(bytes) {
|
|
42
|
+
let out = '';
|
|
43
|
+
for (const b of bytes)
|
|
44
|
+
out += b.toString(16).padStart(2, '0');
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** Minimal big-endian byte representation of a non-negative bigint. */
|
|
48
|
+
export function bigIntToBytesBE(value) {
|
|
49
|
+
let hex = value.toString(16);
|
|
50
|
+
if (hex.length % 2)
|
|
51
|
+
hex = '0' + hex;
|
|
52
|
+
const len = hex.length / 2;
|
|
53
|
+
const out = new Uint8Array(len);
|
|
54
|
+
for (let i = 0; i < len; i++) {
|
|
55
|
+
out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
/** 32-byte big-endian hex string (left-padded). */
|
|
60
|
+
export function toPaddedHexBE(value) {
|
|
61
|
+
const bytes = bigIntToBytesBE(value);
|
|
62
|
+
if (bytes.length > 32)
|
|
63
|
+
throw new Error('Private key is longer than 32 bytes');
|
|
64
|
+
const padded = new Uint8Array(32);
|
|
65
|
+
padded.set(bytes, 32 - bytes.length);
|
|
66
|
+
return bytesToHex(padded);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Reverse the minimal big-endian bytes of `value` into a 32-byte buffer,
|
|
70
|
+
* right-aligned (zero-padded at the front). This matches @portal-hq/eject-js's
|
|
71
|
+
* ed25519 output exactly — including its treatment of scalars with leading
|
|
72
|
+
* zero bytes — so reconstructed keys are byte-identical to the reference.
|
|
73
|
+
* Note: this is NOT a plain left-aligned little-endian encoding.
|
|
74
|
+
*/
|
|
75
|
+
export function toLittleEndian32(value) {
|
|
76
|
+
const bytes = bigIntToBytesBE(value);
|
|
77
|
+
if (bytes.length > 32)
|
|
78
|
+
throw new Error('Private key is longer than 32 bytes');
|
|
79
|
+
const reversed = new Uint8Array(32);
|
|
80
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
81
|
+
reversed[32 - 1 - i] = bytes[i];
|
|
82
|
+
}
|
|
83
|
+
return reversed;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=curves.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curves.js","sourceRoot":"","sources":["../../src/eject/curves.ts"],"names":[],"mappings":"AAIA,gFAAgF;AAChF,MAAM,CAAC,MAAM,WAAW,GAA0B;IAChD,SAAS,EAAE,MAAM,CAAC,oEAAoE,CAAC;IACvF,OAAO,EAAE,MAAM,CAAC,oEAAoE,CAAC;CACtF,CAAC;AAEF,qCAAqC;AACrC,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;IACpD,IAAI,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IACxB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,OA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Ae,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,QAAQ,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAE,CAAC;IACnC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/eject/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,YAAY,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AACpE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eject/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Dense matrix over the integers mod `fieldOrder`. Ported from @portal-hq/eject-js. */
|
|
2
|
+
export declare class Matrix {
|
|
3
|
+
readonly fieldOrder: bigint;
|
|
4
|
+
data: bigint[][];
|
|
5
|
+
rows: number;
|
|
6
|
+
cols: number;
|
|
7
|
+
constructor(fieldOrder: bigint, data: bigint[][]);
|
|
8
|
+
Copy(): Matrix;
|
|
9
|
+
Transpose(): Matrix;
|
|
10
|
+
multiply(other: Matrix): Matrix;
|
|
11
|
+
Inverse(): Matrix;
|
|
12
|
+
modulus(): Matrix;
|
|
13
|
+
GetRow(index: number): bigint[];
|
|
14
|
+
/** (MᵀM)⁻¹Mᵀ — left pseudoinverse, reduced mod field order. */
|
|
15
|
+
Pseudoinverse(): Matrix;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=matrix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../../src/eject/matrix.ts"],"names":[],"mappings":"AAEA,wFAAwF;AACxF,qBAAa,MAAM;IACjB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;gBAED,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;IAOhD,IAAI,IAAI,MAAM;IAOd,SAAS,IAAI,MAAM;IAcnB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAmB/B,OAAO,IAAI,MAAM;IAyCjB,OAAO,IAAI,MAAM;IASjB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAK/B,+DAA+D;IAC/D,aAAa,IAAI,MAAM;CASxB"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { mod, modInverse } from './curves.js';
|
|
2
|
+
/** Dense matrix over the integers mod `fieldOrder`. Ported from @portal-hq/eject-js. */
|
|
3
|
+
export class Matrix {
|
|
4
|
+
fieldOrder;
|
|
5
|
+
data;
|
|
6
|
+
rows;
|
|
7
|
+
cols;
|
|
8
|
+
constructor(fieldOrder, data) {
|
|
9
|
+
this.fieldOrder = fieldOrder;
|
|
10
|
+
this.data = data;
|
|
11
|
+
this.rows = data.length;
|
|
12
|
+
this.cols = data[0]?.length ?? 0;
|
|
13
|
+
}
|
|
14
|
+
Copy() {
|
|
15
|
+
return new Matrix(this.fieldOrder, this.data.map((row) => [...row]));
|
|
16
|
+
}
|
|
17
|
+
Transpose() {
|
|
18
|
+
const newData = Array.from({ length: this.cols }, () => Array.from({ length: this.rows }, () => 0n));
|
|
19
|
+
for (let i = 0; i < this.rows; i++) {
|
|
20
|
+
for (let j = 0; j < this.cols; j++) {
|
|
21
|
+
newData[j][i] = this.data[i][j];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
this.data = newData;
|
|
25
|
+
[this.rows, this.cols] = [this.cols, this.rows];
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
multiply(other) {
|
|
29
|
+
if (this.cols !== other.rows) {
|
|
30
|
+
throw new Error("Matrix dimensions don't match for multiplication");
|
|
31
|
+
}
|
|
32
|
+
const result = Array.from({ length: this.rows }, () => Array.from({ length: other.cols }, () => 0n));
|
|
33
|
+
for (let i = 0; i < this.rows; i++) {
|
|
34
|
+
for (let j = 0; j < other.cols; j++) {
|
|
35
|
+
let acc = 0n;
|
|
36
|
+
for (let k = 0; k < this.cols; k++) {
|
|
37
|
+
acc = (acc + this.data[i][k] * other.data[k][j]) % this.fieldOrder;
|
|
38
|
+
}
|
|
39
|
+
result[i][j] = acc;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return new Matrix(this.fieldOrder, result);
|
|
43
|
+
}
|
|
44
|
+
Inverse() {
|
|
45
|
+
if (this.rows !== this.cols)
|
|
46
|
+
throw new Error('Only square matrices can be inverted');
|
|
47
|
+
const n = this.rows;
|
|
48
|
+
const aug = Array.from({ length: n }, () => Array.from({ length: 2 * n }, () => 0n));
|
|
49
|
+
for (let i = 0; i < n; i++) {
|
|
50
|
+
for (let j = 0; j < n; j++)
|
|
51
|
+
aug[i][j] = this.data[i][j];
|
|
52
|
+
aug[i][i + n] = 1n;
|
|
53
|
+
}
|
|
54
|
+
for (let i = 0; i < n; i++) {
|
|
55
|
+
let pivotRow = i;
|
|
56
|
+
for (let j = i + 1; j < n; j++) {
|
|
57
|
+
if (aug[j][i] !== 0n) {
|
|
58
|
+
pivotRow = j;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (aug[pivotRow][i] === 0n)
|
|
63
|
+
throw new Error('Matrix is singular and cannot be inverted');
|
|
64
|
+
if (pivotRow !== i)
|
|
65
|
+
[aug[i], aug[pivotRow]] = [aug[pivotRow], aug[i]];
|
|
66
|
+
const pivotInv = modInverse(aug[i][i], this.fieldOrder);
|
|
67
|
+
for (let j = 0; j < 2 * n; j++) {
|
|
68
|
+
aug[i][j] = (aug[i][j] * pivotInv) % this.fieldOrder;
|
|
69
|
+
}
|
|
70
|
+
for (let j = 0; j < n; j++) {
|
|
71
|
+
if (j === i)
|
|
72
|
+
continue;
|
|
73
|
+
const factor = aug[j][i];
|
|
74
|
+
for (let k = 0; k < 2 * n; k++) {
|
|
75
|
+
aug[j][k] = mod(aug[j][k] - factor * aug[i][k], this.fieldOrder);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const inverse = Array.from({ length: n }, () => Array.from({ length: n }, () => 0n));
|
|
80
|
+
for (let i = 0; i < n; i++) {
|
|
81
|
+
for (let j = 0; j < n; j++)
|
|
82
|
+
inverse[i][j] = aug[i][j + n];
|
|
83
|
+
}
|
|
84
|
+
return new Matrix(this.fieldOrder, inverse);
|
|
85
|
+
}
|
|
86
|
+
modulus() {
|
|
87
|
+
for (let i = 0; i < this.rows; i++) {
|
|
88
|
+
for (let j = 0; j < this.cols; j++) {
|
|
89
|
+
this.data[i][j] = mod(this.data[i][j], this.fieldOrder);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
GetRow(index) {
|
|
95
|
+
if (index < 0 || index >= this.rows)
|
|
96
|
+
throw new Error('Row index out of bounds');
|
|
97
|
+
return [...this.data[index]];
|
|
98
|
+
}
|
|
99
|
+
/** (MᵀM)⁻¹Mᵀ — left pseudoinverse, reduced mod field order. */
|
|
100
|
+
Pseudoinverse() {
|
|
101
|
+
const copy = this.Copy();
|
|
102
|
+
const copyTranspose = this.Copy().Transpose();
|
|
103
|
+
const symmetric = copyTranspose.multiply(copy);
|
|
104
|
+
const inverseSymmetric = symmetric.Inverse();
|
|
105
|
+
const result = inverseSymmetric.multiply(copyTranspose);
|
|
106
|
+
result.modulus();
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=matrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.js","sourceRoot":"","sources":["../../src/eject/matrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,wFAAwF;AACxF,MAAM,OAAO,MAAM;IACR,UAAU,CAAS;IAC5B,IAAI,CAAa;IACjB,IAAI,CAAS;IACb,IAAI,CAAS;IAEb,YAAY,UAAkB,EAAE,IAAgB;QAC9C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,IAAI;QACF,OAAO,IAAI,MAAM,CACf,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CACjC,CAAC;IACJ,CAAC;IAED,SAAS;QACP,MAAM,OAAO,GAAe,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,CACjE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAC5C,CAAC;QACF,KAAK,IAAI,C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,CAAE,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAChF,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAE,CAAC,CAAC;IAChC,CAAC;IAED,+DAA+D;IAC/D,aAAa;QACX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QACxD,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Curve } from './curves.js';
|
|
2
|
+
import { type ShareInput } from './shares.js';
|
|
3
|
+
export interface ReconstructPrivateKeyParams {
|
|
4
|
+
curve: Curve;
|
|
5
|
+
/** Decrypted client backup share (plaintext of encryptedClientBackupShare). */
|
|
6
|
+
clientShare: ShareInput;
|
|
7
|
+
/** Custodian backup share, as returned by getEjectableBackupShares. */
|
|
8
|
+
custodianShare: ShareInput;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reconstruct a wallet's full private key from its two ejectable backup shares.
|
|
12
|
+
* Returns 64-char big-endian hex for SECP256K1, Base58 for ED25519. Throws on
|
|
13
|
+
* malformed shares or a public-key mismatch.
|
|
14
|
+
*/
|
|
15
|
+
export declare function reconstructPrivateKey(params: ReconstructPrivateKeyParams): Promise<string>;
|
|
16
|
+
//# sourceMappingURL=reconstruct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconstruct.d.ts","sourceRoot":"","sources":["../../src/eject/reconstruct.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,KAAK,KAAK,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAML,KAAK,UAAU,EAChB,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,KAAK,CAAC;IACb,+EAA+E;IAC/E,WAAW,EAAE,UAAU,CAAC;IACxB,uEAAuE;IACvE,cAAc,EAAE,UAAU,CAAC;CAC5B;AA+BD;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,MAAM,CAAC,CAehG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
2
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
3
|
+
import { base58 } from '@scure/base';
|
|
4
|
+
import { computeBkCoefficient } from './birkhoff.js';
|
|
5
|
+
import { FIELD_ORDER, mod, toLittleEndian32, toPaddedHexBE, } from './curves.js';
|
|
6
|
+
import { setupPeers, validateClientShare, validateCustodianShare, } from './shares.js';
|
|
7
|
+
const THRESHOLD = 2;
|
|
8
|
+
/** secret · G, in affine coordinates, for the chosen curve. */
|
|
9
|
+
function derivePublicKeyPoint(curve, secret) {
|
|
10
|
+
const point = curve === 'SECP256K1'
|
|
11
|
+
? secp256k1.Point.BASE.multiply(secret)
|
|
12
|
+
: ed25519.Point.BASE.multiply(secret);
|
|
13
|
+
const { x, y } = point.toAffine();
|
|
14
|
+
return { x, y };
|
|
15
|
+
}
|
|
16
|
+
/** Combine peers into the secret scalar and verify it against the expected pubkey. */
|
|
17
|
+
function recoverScalar(curve, expectedPubkey, peers) {
|
|
18
|
+
const fieldOrder = FIELD_ORDER[curve];
|
|
19
|
+
const coefs = computeBkCoefficient(peers.map((p) => p.bk), THRESHOLD, fieldOrder);
|
|
20
|
+
let secret = 0n;
|
|
21
|
+
for (let i = 0; i < coefs.length; i++) {
|
|
22
|
+
secret = mod(secret + coefs[i] * peers[i].share, fieldOrder);
|
|
23
|
+
}
|
|
24
|
+
const derived = derivePublicKeyPoint(curve, secret);
|
|
25
|
+
if (derived.x !== expectedPubkey.x || derived.y !== expectedPubkey.y) {
|
|
26
|
+
throw new Error('Derived public key does not match expected public key');
|
|
27
|
+
}
|
|
28
|
+
return secret;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reconstruct a wallet's full private key from its two ejectable backup shares.
|
|
32
|
+
* Returns 64-char big-endian hex for SECP256K1, Base58 for ED25519. Throws on
|
|
33
|
+
* malformed shares or a public-key mismatch.
|
|
34
|
+
*/
|
|
35
|
+
export async function reconstructPrivateKey(params) {
|
|
36
|
+
const { curve } = params;
|
|
37
|
+
if (curve !== 'SECP256K1' && curve !== 'ED25519') {
|
|
38
|
+
throw new Error(`Unsupported curve: ${String(curve)}`);
|
|
39
|
+
}
|
|
40
|
+
const client = validateClientShare(params.clientShare);
|
|
41
|
+
const custodian = validateCustodianShare(params.custodianShare);
|
|
42
|
+
const peers = setupPeers({ share: client.share, serverBkX: client.serverBkX }, { share: custodian.share, clientBkX: custodian.clientBkX });
|
|
43
|
+
const secret = recoverScalar(curve, client.pubkey, peers);
|
|
44
|
+
if (curve === 'SECP256K1')
|
|
45
|
+
return toPaddedHexBE(secret);
|
|
46
|
+
return base58.encode(toLittleEndian32(secret));
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=reconstruct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconstruct.js","sourceRoot":"","sources":["../../src/eject/reconstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CA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