@guveno/wallet-sdk 1.0.2 → 1.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 +97 -119
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +5 -1
- package/dist/api/client.js.map +1 -1
- package/dist/api/types.d.ts +10 -1
- package/dist/api/types.d.ts.map +1 -1
- package/dist/encryption-session.d.ts +7 -0
- package/dist/encryption-session.d.ts.map +1 -1
- package/dist/encryption-session.js +8 -1
- package/dist/encryption-session.js.map +1 -1
- package/dist/guveno.d.ts +119 -0
- package/dist/guveno.d.ts.map +1 -0
- package/dist/guveno.js +169 -0
- package/dist/guveno.js.map +1 -0
- package/dist/hot-wallet.d.ts +25 -7
- package/dist/hot-wallet.d.ts.map +1 -1
- package/dist/hot-wallet.js +36 -19
- package/dist/hot-wallet.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/polkadot/silence-esm-cjs-warning.d.ts +2 -0
- package/dist/polkadot/silence-esm-cjs-warning.d.ts.map +1 -0
- package/dist/polkadot/silence-esm-cjs-warning.js +20 -0
- package/dist/polkadot/silence-esm-cjs-warning.js.map +1 -0
- package/dist/signing/sign-bitcoin.d.ts +8 -7
- package/dist/signing/sign-bitcoin.d.ts.map +1 -1
- package/dist/signing/sign-bitcoin.js +39 -31
- package/dist/signing/sign-bitcoin.js.map +1 -1
- package/dist/signing/sign-withdrawal.d.ts +3 -1
- package/dist/signing/sign-withdrawal.d.ts.map +1 -1
- package/dist/signing/sign-withdrawal.js +5 -2
- package/dist/signing/sign-withdrawal.js.map +1 -1
- package/dist/signing/types.d.ts +8 -0
- package/dist/signing/types.d.ts.map +1 -1
- package/dist/signing/types.js.map +1 -1
- package/dist/wallet.d.ts +63 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +84 -0
- package/dist/wallet.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Silence @polkadot's "multiple versions" console warning.
|
|
3
|
+
*
|
|
4
|
+
* `@substrate/txwrapper-polkadot` is CommonJS-only, so it `require()`s the CJS
|
|
5
|
+
* build of `@polkadot/util` (et al.) while the SDK's own ESM code imports the
|
|
6
|
+
* ESM build. That loads two module formats of the *same* version (e.g. 13.5.9)
|
|
7
|
+
* into one process, which `@polkadot/util`'s `detectPackage` reports as a
|
|
8
|
+
* dedupe warning. It's a false positive here — the wasm/crypto state is
|
|
9
|
+
* identical across the two builds — so we opt out via the library's own flag.
|
|
10
|
+
*
|
|
11
|
+
* `detectPackage` only honors the flag when every loaded entry is the same
|
|
12
|
+
* version, so a genuine version mismatch still warns. We use `??=` so a
|
|
13
|
+
* consumer who set the flag explicitly (e.g. to `'0'`) keeps their choice.
|
|
14
|
+
*
|
|
15
|
+
* This MUST be imported before any `@polkadot/*` module is evaluated, hence it
|
|
16
|
+
* is the first import in `src/index.ts`.
|
|
17
|
+
*/
|
|
18
|
+
process.env.POLKADOTJS_DISABLE_ESM_CJS_WARNING ??= '1';
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=silence-esm-cjs-warning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"silence-esm-cjs-warning.js","sourceRoot":"","sources":["../../src/polkadot/silence-esm-cjs-warning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,CAAC,GAAG,CAAC,kCAAkC,KAAK,GAAG,CAAC"}
|
|
@@ -3,12 +3,13 @@ import type { SigningPayload } from './types.js';
|
|
|
3
3
|
* Builds and signs a P2WPKH (native SegWit) Bitcoin withdrawal for a prepared
|
|
4
4
|
* payload, returning the signed raw transaction hex the server broadcasts.
|
|
5
5
|
*
|
|
6
|
-
* The server selects the
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
6
|
+
* The server coin-selects the inputs — possibly aggregated across several of the
|
|
7
|
+
* wallet's addresses — and supplies the fee rate and change address. This signer
|
|
8
|
+
* spends all of them (deriving a key per input from its own derivation path),
|
|
9
|
+
* pays the requested output(s), computes the fee from the fee rate and the
|
|
10
|
+
* transaction's virtual size, and returns the remainder as change to the wallet's
|
|
11
|
+
* change address (dropping it into the fee when it would be dust). Keys are
|
|
12
|
+
* derived in-process from the mnemonic and never leave the caller.
|
|
12
13
|
*/
|
|
13
|
-
export declare function signBitcoinWithdrawal(payload: SigningPayload, mnemonic: string,
|
|
14
|
+
export declare function signBitcoinWithdrawal(payload: SigningPayload, mnemonic: string, feeRateOverride?: number): string;
|
|
14
15
|
//# sourceMappingURL=sign-bitcoin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign-bitcoin.d.ts","sourceRoot":"","sources":["../../src/signing/sign-bitcoin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoC,cAAc,EAAE,MAAM,YAAY,CAAC;AA6CnF
|
|
1
|
+
{"version":3,"file":"sign-bitcoin.d.ts","sourceRoot":"","sources":["../../src/signing/sign-bitcoin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoC,cAAc,EAAE,MAAM,YAAY,CAAC;AA6CnF;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAsGjH"}
|
|
@@ -44,34 +44,40 @@ function toBaseUnits(amount, decimals) {
|
|
|
44
44
|
* Builds and signs a P2WPKH (native SegWit) Bitcoin withdrawal for a prepared
|
|
45
45
|
* payload, returning the signed raw transaction hex the server broadcasts.
|
|
46
46
|
*
|
|
47
|
-
* The server selects the
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
47
|
+
* The server coin-selects the inputs — possibly aggregated across several of the
|
|
48
|
+
* wallet's addresses — and supplies the fee rate and change address. This signer
|
|
49
|
+
* spends all of them (deriving a key per input from its own derivation path),
|
|
50
|
+
* pays the requested output(s), computes the fee from the fee rate and the
|
|
51
|
+
* transaction's virtual size, and returns the remainder as change to the wallet's
|
|
52
|
+
* change address (dropping it into the fee when it would be dust). Keys are
|
|
53
|
+
* derived in-process from the mnemonic and never leave the caller.
|
|
53
54
|
*/
|
|
54
|
-
export function signBitcoinWithdrawal(payload, mnemonic,
|
|
55
|
+
export function signBitcoinWithdrawal(payload, mnemonic, feeRateOverride) {
|
|
55
56
|
const state = payload.chainState;
|
|
56
57
|
if (state == null) {
|
|
57
58
|
throw new Error('Missing Bitcoin chain state from the server.');
|
|
58
59
|
}
|
|
59
60
|
if (!Array.isArray(state.utxos) || state.utxos.length === 0) {
|
|
60
|
-
throw new Error('No spendable UTXOs are available for this
|
|
61
|
+
throw new Error('No spendable UTXOs are available for this withdrawal.');
|
|
61
62
|
}
|
|
62
63
|
const network = payload.network === 'testnet' ? networks.testnet : networks.bitcoin;
|
|
63
64
|
const seed = mnemonicToSeedSync(mnemonic);
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
const root = bip32.fromSeed(Buffer.from(seed), network);
|
|
66
|
+
// Derive a key + witness script per input from its own derivation path (inputs
|
|
67
|
+
// may span several addresses when aggregated). Each derived address must match
|
|
68
|
+
// the one the server tagged the UTXO with — a mismatch means a wrong
|
|
69
|
+
// path/mnemonic, so fail before signing.
|
|
70
|
+
const inputs = state.utxos.map((utxo) => {
|
|
71
|
+
const node = root.derivePath(utxo.derivationPath);
|
|
72
|
+
const payment = payments.p2wpkh({ pubkey: Buffer.from(node.publicKey), network });
|
|
73
|
+
if (payment.address == null || payment.output == null) {
|
|
74
|
+
throw new Error('Unable to derive the Bitcoin signing key.');
|
|
75
|
+
}
|
|
76
|
+
if (payment.address !== utxo.address) {
|
|
77
|
+
throw new Error(`Derived address ${payment.address} does not match the UTXO's address ${utxo.address}.`);
|
|
78
|
+
}
|
|
79
|
+
return { utxo, node, script: Buffer.from(payment.output) };
|
|
80
|
+
});
|
|
75
81
|
const decimals = payload.asset.decimals;
|
|
76
82
|
const recipients = payload.outputs != null && payload.outputs.length > 0
|
|
77
83
|
? payload.outputs
|
|
@@ -90,12 +96,14 @@ export function signBitcoinWithdrawal(payload, mnemonic, derivationPath) {
|
|
|
90
96
|
}
|
|
91
97
|
return { value, script: btcAddress.toOutputScript(recipient.toAddress, network) };
|
|
92
98
|
});
|
|
93
|
-
const totalIn =
|
|
99
|
+
const totalIn = inputs.reduce((sum, input) => sum + BigInt(input.utxo.value), 0n);
|
|
94
100
|
const totalOut = outputs.reduce((sum, output) => sum + output.value, 0n);
|
|
95
|
-
|
|
101
|
+
// sat/vB: caller's override (>= 1) or the server's suggestion. Inputs are fixed
|
|
102
|
+
// at prepare time, so a much higher rate may exceed what they cover (caught below).
|
|
103
|
+
const feeRate = BigInt(Math.max(1, Math.ceil(feeRateOverride != null && feeRateOverride >= 1 ? feeRateOverride : state.feeRate)));
|
|
96
104
|
const changeScript = btcAddress.toOutputScript(state.changeAddress ?? payload.sourceAddress, network);
|
|
97
105
|
const baseVbytes = TX_OVERHEAD_VBYTES +
|
|
98
|
-
|
|
106
|
+
inputs.length * P2WPKH_INPUT_VBYTES +
|
|
99
107
|
outputs.reduce((sum, output) => sum + outputVbytes(output.script), 0);
|
|
100
108
|
// First assume a change output exists; if the leftover is dust, drop it and let
|
|
101
109
|
// the whole remainder be the fee.
|
|
@@ -112,21 +120,21 @@ export function signBitcoinWithdrawal(payload, mnemonic, derivationPath) {
|
|
|
112
120
|
}
|
|
113
121
|
}
|
|
114
122
|
const psbt = new Psbt({ network });
|
|
115
|
-
for (const
|
|
123
|
+
for (const input of inputs) {
|
|
116
124
|
psbt.addInput({
|
|
117
|
-
hash: utxo.txid,
|
|
118
|
-
index: utxo.vout,
|
|
119
|
-
witnessUtxo: { script:
|
|
125
|
+
hash: input.utxo.txid,
|
|
126
|
+
index: input.utxo.vout,
|
|
127
|
+
witnessUtxo: { script: input.script, value: BigInt(input.utxo.value) },
|
|
120
128
|
});
|
|
121
129
|
}
|
|
122
130
|
for (const output of finalOutputs) {
|
|
123
131
|
psbt.addOutput({ script: output.script, value: output.value });
|
|
124
132
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
// Sign each input with the key for its own address.
|
|
134
|
+
inputs.forEach((input, i) => psbt.signInput(i, {
|
|
135
|
+
publicKey: Buffer.from(input.node.publicKey),
|
|
136
|
+
sign: (hash) => Buffer.from(input.node.sign(hash)),
|
|
137
|
+
}));
|
|
130
138
|
psbt.finalizeAllInputs();
|
|
131
139
|
return psbt.extractTransaction().toHex();
|
|
132
140
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign-bitcoin.js","sourceRoot":"","sources":["../../src/signing/sign-bitcoin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AAGtC,UAAU,CAAC,GAAG,CAAC,CAAC;AAChB,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;AAEhC,iFAAiF;AACjF,kFAAkF;AAClF,iEAAiE;AACjE,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B,kFAAkF;AAClF,4EAA4E;AAC5E,sFAAsF;AACtF,+EAA+E;AA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,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI;YACrB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI;YACtB,WAAW,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;SACvE,CAAC,CAAC;IACL,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,YAAY,EAAE,CAAC;QAClC,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,oDAAoD;IACpD,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAC1B,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE;QAChB,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;QAC5C,IAAI,EAAE,CAAC,IAAY,EAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACnE,CAAC,CACH,CAAC;IACF,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAEzB,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC,KAAK,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -8,13 +8,15 @@ export interface SignWithdrawalInput {
|
|
|
8
8
|
derivationPath: string;
|
|
9
9
|
/** Caller-customized Ethereum gas (wei / units); falls back to server suggestions. */
|
|
10
10
|
ethereumGas?: EthereumGasOverrides;
|
|
11
|
+
/** Caller-customized Bitcoin fee rate (sat/vB); falls back to the server suggestion. */
|
|
12
|
+
bitcoinFeeRate?: number;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Produces a fully-signed raw transaction (hex) for a prepared withdrawal. Pure — no
|
|
14
16
|
* network access. New chains are added here as their per-chain signer + server chain
|
|
15
17
|
* state land.
|
|
16
18
|
*/
|
|
17
|
-
export declare function signWithdrawal({ payload, mnemonic, derivationPath, ethereumGas }: SignWithdrawalInput): Promise<string>;
|
|
19
|
+
export declare function signWithdrawal({ payload, mnemonic, derivationPath, ethereumGas, bitcoinFeeRate }: SignWithdrawalInput): Promise<string>;
|
|
18
20
|
/** Chains the SDK signer currently supports. */
|
|
19
21
|
export declare const SIGNABLE_CHAINS: readonly ["ethereum", "xrp", "bitcoin", "polkadot"];
|
|
20
22
|
export declare function canSignChain(chain: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign-withdrawal.d.ts","sourceRoot":"","sources":["../../src/signing/sign-withdrawal.ts"],"names":[],"mappings":"AAEA,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAGvF,OAAO,EAAmD,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAElG,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,cAAc,CAAC;IACxB,2FAA2F;IAC3F,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,cAAc,EAAE,MAAM,CAAC;IACvB,sFAAsF;IACtF,WAAW,CAAC,EAAE,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"sign-withdrawal.d.ts","sourceRoot":"","sources":["../../src/signing/sign-withdrawal.ts"],"names":[],"mappings":"AAEA,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAGvF,OAAO,EAAmD,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAElG,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,cAAc,CAAC;IACxB,2FAA2F;IAC3F,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,cAAc,EAAE,MAAM,CAAC;IACvB,sFAAsF;IACtF,WAAW,CAAC,EAAE,oBAAoB,CAAC;IACnC,wFAAwF;IACxF,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,QAAQ,EACR,cAAc,EACd,WAAW,EACX,cAAc,EACf,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBvC;AAED,gDAAgD;AAChD,eAAO,MAAM,eAAe,qDAAsD,CAAC;AAEnF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnD"}
|
|
@@ -9,7 +9,7 @@ import { UnsupportedSigningError, WithdrawalExpiredError } from './types.js';
|
|
|
9
9
|
* network access. New chains are added here as their per-chain signer + server chain
|
|
10
10
|
* state land.
|
|
11
11
|
*/
|
|
12
|
-
export async function signWithdrawal({ payload, mnemonic, derivationPath, ethereumGas }) {
|
|
12
|
+
export async function signWithdrawal({ payload, mnemonic, derivationPath, ethereumGas, bitcoinFeeRate }) {
|
|
13
13
|
assertValidMnemonic(mnemonic);
|
|
14
14
|
if (Date.now() >= new Date(payload.expiresAt).getTime()) {
|
|
15
15
|
throw new WithdrawalExpiredError();
|
|
@@ -20,7 +20,10 @@ export async function signWithdrawal({ payload, mnemonic, derivationPath, ethere
|
|
|
20
20
|
case 'xrp':
|
|
21
21
|
return signXrpWithdrawal(payload, mnemonic, derivationPath);
|
|
22
22
|
case 'bitcoin':
|
|
23
|
-
|
|
23
|
+
// Bitcoin derives a key per input from each UTXO's own path (in chainState),
|
|
24
|
+
// so the address-level derivationPath isn't used here. An optional fee-rate
|
|
25
|
+
// override (sat/vB) replaces the server's suggestion.
|
|
26
|
+
return signBitcoinWithdrawal(payload, mnemonic, bitcoinFeeRate);
|
|
24
27
|
case 'polkadot':
|
|
25
28
|
return signPolkadotWithdrawal(payload, mnemonic, derivationPath);
|
|
26
29
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign-withdrawal.js","sourceRoot":"","sources":["../../src/signing/sign-withdrawal.ts"],"names":[],"mappings":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,KAAK;YACR,OAAO,iBAAiB,CAAC,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;QAC9D,KAAK,SAAS;YACZ,6EAA6E;YAC7E,4EAA4E;YAC5E,sDAAsD;YACtD,OAAO,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;QAClE,KAAK,UAAU;YACb,OAAO,sBAAsB,CAAC,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;QACnE;YACE,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAED,gDAAgD;AAChD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC;AAEnF,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAQ,eAAqC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/signing/types.d.ts
CHANGED
|
@@ -16,13 +16,21 @@ export interface EthereumChainState {
|
|
|
16
16
|
gasLimit: string;
|
|
17
17
|
}
|
|
18
18
|
export interface BitcoinChainState {
|
|
19
|
+
/**
|
|
20
|
+
* The exact inputs the server coin-selected (already covering amount + fee).
|
|
21
|
+
* Each carries its owning address + derivation path so an aggregated tx can
|
|
22
|
+
* sign every input with the right key.
|
|
23
|
+
*/
|
|
19
24
|
utxos: Array<{
|
|
20
25
|
txid: string;
|
|
21
26
|
vout: number;
|
|
22
27
|
value: number;
|
|
28
|
+
address: string;
|
|
29
|
+
derivationPath: string;
|
|
23
30
|
scriptPubKey?: string;
|
|
24
31
|
}>;
|
|
25
32
|
feeRate: number;
|
|
33
|
+
/** Wallet-owned address that any change output returns to. */
|
|
26
34
|
changeAddress: string;
|
|
27
35
|
}
|
|
28
36
|
export interface XrpChainState {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/signing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpE,wGAAwG;AACxG,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/signing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpE,wGAAwG;AACxG,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE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EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,uFAAuF;IACvF,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,gFAAgF;AAChF,qBAAa,sBAAuB,SAAQ,KAAK;;CAKhD;AAED,iEAAiE;AACjE,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,KAAK,EAAE,MAAM;CAI1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/signing/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/signing/types.ts"],"names":[],"mappings":"AAqFA,gFAAgF;AAChF,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C;QACE,KAAK,CAAC,kEAAkE,CAAC,CAAC;QAC1E,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,iEAAiE;AACjE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAAY,KAAa;QACvB,KAAK,CAAC,cAAc,KAAK,wBAAwB,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF"}
|
package/dist/wallet.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { GuvenoApiClient } from './api/client.js';
|
|
2
|
+
import type { ApiPageInfo, ApiWalletAddress, ApiWalletDetail, ListApiAddressOptions } from './api/types.js';
|
|
3
|
+
import type { ApiChain, ApiNetwork, ApiWithdrawal } from './api/types.js';
|
|
4
|
+
import type { EncryptionSession } from './encryption-session.js';
|
|
5
|
+
import { type WithdrawInput } from './hot-wallet.js';
|
|
6
|
+
import type { KeyProvider } from './keyprovider/index.js';
|
|
7
|
+
import { type DeriveAddressOptions, type DeriveAddressResult } from './wallet-service.js';
|
|
8
|
+
/**
|
|
9
|
+
* A withdrawal request from a loaded wallet. The wallet is implied, so `walletId`
|
|
10
|
+
* is omitted — pass the source `addressId` and the asset/amount/destination.
|
|
11
|
+
*/
|
|
12
|
+
export type WalletWithdrawInput = Omit<WithdrawInput, 'walletId'>;
|
|
13
|
+
export interface WalletDeps {
|
|
14
|
+
api: GuvenoApiClient;
|
|
15
|
+
detail: ApiWalletDetail;
|
|
16
|
+
/** Server-source-of-truth mode: unlocked with the user's encryption password. */
|
|
17
|
+
session?: EncryptionSession;
|
|
18
|
+
/** Headless mode: the recovery phrase is sourced from a KMS/HSM/file provider. */
|
|
19
|
+
keys?: KeyProvider;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A single wallet, ready to use. Returned by {@link Guveno.loadWallet},
|
|
23
|
+
* {@link Guveno.createWallet}, and {@link Guveno.importWallet}. The signing key
|
|
24
|
+
* is already resolved (either the unlocked encryption key, or a key provider), so
|
|
25
|
+
* you can withdraw, derive addresses, and reveal the recovery phrase without
|
|
26
|
+
* re-supplying credentials.
|
|
27
|
+
*/
|
|
28
|
+
export declare class Wallet {
|
|
29
|
+
private readonly api;
|
|
30
|
+
private readonly session;
|
|
31
|
+
private readonly hot;
|
|
32
|
+
private readonly service;
|
|
33
|
+
private walletDetail;
|
|
34
|
+
constructor(deps: WalletDeps);
|
|
35
|
+
/** The wallet's server id. */
|
|
36
|
+
get id(): number;
|
|
37
|
+
get name(): string;
|
|
38
|
+
get chain(): ApiChain;
|
|
39
|
+
get network(): ApiNetwork;
|
|
40
|
+
/** The underlying server record, e.g. for display. */
|
|
41
|
+
get detail(): ApiWalletDetail;
|
|
42
|
+
/** Prepare, sign locally, and broadcast a withdrawal from one of this wallet's addresses. */
|
|
43
|
+
withdraw(input: WalletWithdrawInput): Promise<ApiWithdrawal>;
|
|
44
|
+
/** Fetch the current state of a withdrawal (e.g. to poll for confirmation). */
|
|
45
|
+
getWithdrawal(withdrawalId: number): Promise<ApiWithdrawal>;
|
|
46
|
+
/** List the addresses registered for this wallet. */
|
|
47
|
+
listAddresses(options?: ListApiAddressOptions): Promise<{
|
|
48
|
+
items: ApiWalletAddress[];
|
|
49
|
+
pageInfo: ApiPageInfo;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Derive and register the next address (uses the server's `nextAccountIndex`).
|
|
53
|
+
* Requires loading the wallet with your encryption password — a key provider
|
|
54
|
+
* can't seal against the server.
|
|
55
|
+
*/
|
|
56
|
+
deriveAddress(options?: DeriveAddressOptions): Promise<DeriveAddressResult>;
|
|
57
|
+
/** Fetch and decrypt this wallet's recovery phrase from the server (audited). */
|
|
58
|
+
revealMnemonic(): Promise<string>;
|
|
59
|
+
/** Wipe the unlocked key material from memory. The wallet can't sign afterwards. */
|
|
60
|
+
lock(): void;
|
|
61
|
+
private requireService;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,EAAa,K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EAAE,WAAW,CAAA;KAAE,CAAC;IAIhE;;;;OAIG;IACG,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAMrF,iFAAiF;IAC3E,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvC,oFAAoF;IACpF,IAAI,IAAI,IAAI;IAIZ,OAAO,CAAC,cAAc;CAQvB"}
|
package/dist/wallet.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ValidationError } from './errors.js';
|
|
2
|
+
import { HotWallet } from './hot-wallet.js';
|
|
3
|
+
import { WalletService } from './wallet-service.js';
|
|
4
|
+
/**
|
|
5
|
+
* A single wallet, ready to use. Returned by {@link Guveno.loadWallet},
|
|
6
|
+
* {@link Guveno.createWallet}, and {@link Guveno.importWallet}. The signing key
|
|
7
|
+
* is already resolved (either the unlocked encryption key, or a key provider), so
|
|
8
|
+
* you can withdraw, derive addresses, and reveal the recovery phrase without
|
|
9
|
+
* re-supplying credentials.
|
|
10
|
+
*/
|
|
11
|
+
export class Wallet {
|
|
12
|
+
api;
|
|
13
|
+
session;
|
|
14
|
+
hot;
|
|
15
|
+
// Only available in encryption-password (session) mode — derive/reveal need to
|
|
16
|
+
// seal/unseal against the server, which a bare key provider can't do.
|
|
17
|
+
service;
|
|
18
|
+
walletDetail;
|
|
19
|
+
constructor(deps) {
|
|
20
|
+
this.api = deps.api;
|
|
21
|
+
this.session = deps.session;
|
|
22
|
+
this.walletDetail = deps.detail;
|
|
23
|
+
this.hot = new HotWallet({
|
|
24
|
+
api: deps.api,
|
|
25
|
+
...(deps.session != null ? { session: deps.session } : {}),
|
|
26
|
+
...(deps.keys != null ? { keys: deps.keys } : {})
|
|
27
|
+
});
|
|
28
|
+
this.service = deps.session != null ? new WalletService({ api: deps.api, session: deps.session }) : undefined;
|
|
29
|
+
}
|
|
30
|
+
/** The wallet's server id. */
|
|
31
|
+
get id() {
|
|
32
|
+
return this.walletDetail.id;
|
|
33
|
+
}
|
|
34
|
+
get name() {
|
|
35
|
+
return this.walletDetail.name;
|
|
36
|
+
}
|
|
37
|
+
get chain() {
|
|
38
|
+
return this.walletDetail.chain;
|
|
39
|
+
}
|
|
40
|
+
get network() {
|
|
41
|
+
return this.walletDetail.network;
|
|
42
|
+
}
|
|
43
|
+
/** The underlying server record, e.g. for display. */
|
|
44
|
+
get detail() {
|
|
45
|
+
return this.walletDetail;
|
|
46
|
+
}
|
|
47
|
+
/** Prepare, sign locally, and broadcast a withdrawal from one of this wallet's addresses. */
|
|
48
|
+
async withdraw(input) {
|
|
49
|
+
return this.hot.withdraw({ ...input, walletId: this.walletDetail.id });
|
|
50
|
+
}
|
|
51
|
+
/** Fetch the current state of a withdrawal (e.g. to poll for confirmation). */
|
|
52
|
+
async getWithdrawal(withdrawalId) {
|
|
53
|
+
return this.api.getWithdrawal(withdrawalId);
|
|
54
|
+
}
|
|
55
|
+
/** List the addresses registered for this wallet. */
|
|
56
|
+
async listAddresses(options = {}) {
|
|
57
|
+
return this.api.listWalletAddresses(this.walletDetail.id, options);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Derive and register the next address (uses the server's `nextAccountIndex`).
|
|
61
|
+
* Requires loading the wallet with your encryption password — a key provider
|
|
62
|
+
* can't seal against the server.
|
|
63
|
+
*/
|
|
64
|
+
async deriveAddress(options = {}) {
|
|
65
|
+
const result = await this.requireService('deriveAddress').deriveAddress(this.walletDetail.id, options);
|
|
66
|
+
this.walletDetail = result.wallet;
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
/** Fetch and decrypt this wallet's recovery phrase from the server (audited). */
|
|
70
|
+
async revealMnemonic() {
|
|
71
|
+
return this.requireService('revealMnemonic').revealMnemonic(this.walletDetail.id);
|
|
72
|
+
}
|
|
73
|
+
/** Wipe the unlocked key material from memory. The wallet can't sign afterwards. */
|
|
74
|
+
lock() {
|
|
75
|
+
this.session?.lock();
|
|
76
|
+
}
|
|
77
|
+
requireService(method) {
|
|
78
|
+
if (this.service == null) {
|
|
79
|
+
throw new ValidationError(`${method}() needs the wallet loaded with your encryption password; it isn't available when signing from a key provider.`);
|
|
80
|
+
}
|
|
81
|
+
return this.service;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAsB,MAAM,iBAAiB,CAAC;AAEhE,OAAO,EAAE,aAAa,EAAuD,MAAM,qBAAqB,CAAC;AAiBzG;;;;;;GAMG;AACH,MAAM,OAAO,MAAM;IACA,GAAG,CAAkB;IACrB,OAAO,CAAgC;IACvC,GAAG,CAAY;IAChC,+EAA+E;IAC/E,sEAAsE;IACrD,OAAO,CAA4B;IAC5C,YAAY,CAAkB;IAEtC,YAAY,IAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC;QAChC,IAAI,CAAC,GAAG,GAAG,IAAI,SAAS,CAAC;YACvB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAClD,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAA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AC,EAAE,EAAE,OAAO,CAAC,CAAC;QACvG,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;QAClC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,iFAAiF;IACjF,KAAK,CAAC,cAAc;QAClB,OAAO,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IACpF,CAAC;IAED,oFAAoF;IACpF,IAAI;QACF,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;IACvB,CAAC;IAEO,cAAc,CAAC,MAAc;QACnC,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YACzB,MAAM,IAAI,eAAe,CACvB,GAAG,MAAM,gHAAgH,CAC1H,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guveno/wallet-sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Add secure crypto custody to your app in minutes — create and manage multi-chain wallets, automate withdrawals, and receive real-time webhooks for Bitcoin, Ethereum, XRP, and Polkadot. Built for exchanges, fintechs, and platforms.",
|
|
5
5
|
"author": "Guveno LLC",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"crypto",
|
|
27
27
|
"custody"
|
|
28
28
|
],
|
|
29
|
-
"homepage": "https://guveno.com",
|
|
29
|
+
"homepage": "https://www.guveno.com/docs",
|
|
30
30
|
"files": [
|
|
31
31
|
"dist",
|
|
32
32
|
"README.md",
|