@sidhujag/sysweb3-keyring 2.1.0 → 2.1.2
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/CHANGELOG.md +14 -0
- package/README.md +46 -108
- package/cjs/evm-fees.js +223 -0
- package/cjs/evm-fees.js.map +1 -0
- package/cjs/keyring-core.js +1 -227
- package/cjs/keyring-core.js.map +1 -1
- package/cjs/keyring-manager.js +4 -3
- package/cjs/keyring-manager.js.map +1 -1
- package/cjs/software.js +12 -11
- package/cjs/software.js.map +1 -1
- package/cjs/transactions/ethereum.js +268 -195
- package/cjs/transactions/ethereum.js.map +1 -1
- package/cjs/transactions/evm-local-signer.js +31 -8
- package/cjs/transactions/evm-local-signer.js.map +1 -1
- package/cjs/transactions/evm-submission.js +200 -0
- package/cjs/transactions/evm-submission.js.map +1 -0
- package/cjs/transactions/index.js +1 -0
- package/cjs/transactions/index.js.map +1 -1
- package/cjs/transactions/prepared-evm.js +5 -6
- package/cjs/transactions/prepared-evm.js.map +1 -1
- package/cjs/types.js.map +1 -1
- package/cjs/utils/derivation-paths.js +4 -3
- package/cjs/utils/derivation-paths.js.map +1 -1
- package/cjs/utils/watch-descriptor.js +3 -2
- package/cjs/utils/watch-descriptor.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/derivation-paths.js +2 -1
- package/esm/utils/derivation-paths.js.map +1 -1
- package/package.json +24 -11
- package/types/evm-fees.d.ts +42 -0
- package/types/keyring-core.d.ts +3 -8
- package/types/keyring-manager.d.ts +8 -3
- package/types/software.d.ts +6 -11
- package/types/transactions/ethereum.d.ts +10 -8
- package/types/transactions/evm-local-signer.d.ts +4 -1
- package/types/transactions/evm-submission.d.ts +51 -0
- package/types/transactions/index.d.ts +1 -0
- package/types/types.d.ts +4 -0
- package/cjs/bip84-native.js +0 -8
- package/cjs/bip84-native.js.map +0 -1
- package/cjs/public-bip84.js +0 -157
- package/cjs/public-bip84.js.map +0 -1
- package/cjs/software-utxo-account.js +0 -12
- package/cjs/software-utxo-account.js.map +0 -1
- package/cjs/transactions/bip84-native-plan.js +0 -481
- package/cjs/transactions/bip84-native-plan.js.map +0 -1
- package/cjs/transactions/prepared-bip84.js +0 -214
- package/cjs/transactions/prepared-bip84.js.map +0 -1
- package/types/bip84-native.d.ts +0 -3
- package/types/public-bip84.d.ts +0 -39
- package/types/software-utxo-account.d.ts +0 -13
- package/types/transactions/bip84-native-plan.d.ts +0 -83
- package/types/transactions/prepared-bip84.d.ts +0 -27
package/types/software.d.ts
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
import { KeyringCore } from './keyring-core';
|
|
3
3
|
import type { KeyringStoragePort } from './keyring-core';
|
|
4
4
|
import type { EncryptedEvmHdRuntimeAccount, EvmHdRuntimeAccountOptions, EvmHdRuntimeAccountRequest } from './software-hd-account';
|
|
5
|
-
import type {
|
|
6
|
-
import type { Bip84Guard } from './transactions/bip84-native-plan';
|
|
7
|
-
import type { PreparedBip84SigningRequest, SignedBip84NativeTransaction } from './transactions/prepared-bip84';
|
|
5
|
+
import type { CaptureEvmSubmission } from './transactions/evm-submission';
|
|
8
6
|
import type { PreparedEvmSigningOptions, PreparedSoftwareEvmSigningRequest, SignedPreparedEvmTransaction } from './transactions/prepared-evm';
|
|
9
7
|
declare const softwareHostBrand: unique symbol;
|
|
10
8
|
/** Opaque handle minted by createSoftwareKeyringHost; no injectable persistence. */
|
|
@@ -12,7 +10,9 @@ export interface SoftwareKeyringHost {
|
|
|
12
10
|
readonly [softwareHostBrand]: true;
|
|
13
11
|
}
|
|
14
12
|
/** Create once per wallet authority, then share with its per-network keyrings. */
|
|
15
|
-
export declare const createSoftwareKeyringHost: (storage: KeyringStoragePort
|
|
13
|
+
export declare const createSoftwareKeyringHost: (storage: KeyringStoragePort, options?: {
|
|
14
|
+
captureEvmSubmission?: CaptureEvmSubmission;
|
|
15
|
+
}) => SoftwareKeyringHost;
|
|
16
16
|
export declare class SoftwareKeyring extends KeyringCore<undefined, undefined> {
|
|
17
17
|
constructor(host: SoftwareKeyringHost);
|
|
18
18
|
/**
|
|
@@ -21,10 +21,6 @@ export declare class SoftwareKeyring extends KeyringCore<undefined, undefined> {
|
|
|
21
21
|
* never a public account/catalogue DTO. The host owns index allocation.
|
|
22
22
|
*/
|
|
23
23
|
deriveEvmHdRuntimeAccount(request: EvmHdRuntimeAccountRequest, options: EvmHdRuntimeAccountOptions): Promise<EncryptedEvmHdRuntimeAccount>;
|
|
24
|
-
/** Derive public BIP84 account data from the live seed; no storage or discovery. */
|
|
25
|
-
deriveBip84HdPublicAccount(request: Bip84HdPublicRequest, options: Bip84Guard): Promise<Bip84HdPublicResult>;
|
|
26
|
-
/** Sign the selected HD account's exact prepared native transaction offline. */
|
|
27
|
-
signPreparedBip84Transaction(request: PreparedBip84SigningRequest, options: Bip84Guard): Promise<SignedBip84NativeTransaction>;
|
|
28
24
|
/**
|
|
29
25
|
* Sign exactly the prepared envelope without RPC, fee/nonce discovery or
|
|
30
26
|
* broadcasting. The host must journal the result before submitting it.
|
|
@@ -44,6 +40,5 @@ export type { KeyringStoragePort } from './keyring-core';
|
|
|
44
40
|
export type { IKeyringAccountState } from './types';
|
|
45
41
|
export type { PreparedEvmTransaction, PreparedEvmSigningOptions, PreparedSoftwareEvmSigningRequest, SignedPreparedEvmTransaction, } from './transactions/prepared-evm';
|
|
46
42
|
export type { EncryptedEvmHdRuntimeAccount, EvmHdRuntimeAccountOptions, EvmHdRuntimeAccountRequest, } from './software-hd-account';
|
|
47
|
-
export
|
|
48
|
-
export type {
|
|
49
|
-
export type { PreparedBip84SigningRequest, SignedBip84NativeTransaction, } from './transactions/prepared-bip84';
|
|
43
|
+
export { captureEvmSubmission, submitSignedEvmTransaction, evmSubmissionFailure, } from './transactions/evm-submission';
|
|
44
|
+
export type { CaptureEvmSubmission, EvmSubmissionContext, EvmSubmissionLifecycle, EvmSignedSubmission, EvmSubmissionBoundary, } from './transactions/evm-submission';
|
|
@@ -3,6 +3,7 @@ import { INetwork } from '@sidhujag/sysweb3-network';
|
|
|
3
3
|
import { BigNumber, TransactionResponse } from '../ethers-v6';
|
|
4
4
|
import { CustomJsonRpcProvider } from '../providers';
|
|
5
5
|
import { IResponseFromSendErcSignedTransaction, ISendSignedErcTransactionProps, IEthereumTransactions, IEvmCancellationOptions, IEvmReplacementOptions, IEvmSendOptions, SimpleTransactionRequest, KeyringAccountType, accountType, IGasParams } from '../types';
|
|
6
|
+
import { type CaptureEvmSubmission } from './evm-submission';
|
|
6
7
|
import type { LedgerKeyring } from '../ledger';
|
|
7
8
|
import type { TrezorKeyring } from '../trezor';
|
|
8
9
|
/** Minimal trusted device capabilities used by EVM transaction routing. */
|
|
@@ -18,6 +19,7 @@ export declare class EthereumTransactions<TLedger extends EthereumLedgerSigner |
|
|
|
18
19
|
ledgerSigner: TLedger;
|
|
19
20
|
private getNetwork;
|
|
20
21
|
private captureSigningContext?;
|
|
22
|
+
private readonly captureSubmissionLifecycle?;
|
|
21
23
|
private abortController;
|
|
22
24
|
private getDecryptedPrivateKey;
|
|
23
25
|
private gasOverrides;
|
|
@@ -35,11 +37,12 @@ export declare class EthereumTransactions<TLedger extends EthereumLedgerSigner |
|
|
|
35
37
|
activeAccountId: number;
|
|
36
38
|
activeAccountType: KeyringAccountType;
|
|
37
39
|
activeNetwork: INetwork;
|
|
38
|
-
}, ledgerSigner: TLedger, trezorSigner: TTrezor, captureSigningContext?: () => () => void);
|
|
40
|
+
}, ledgerSigner: TLedger, trezorSigner: TTrezor, captureSigningContext?: () => () => void, captureSubmissionLifecycle?: CaptureEvmSubmission);
|
|
39
41
|
private requireLedgerSigner;
|
|
40
42
|
private requireTrezorSigner;
|
|
41
43
|
private assertHardwareSignerAvailable;
|
|
42
44
|
private captureEvmSigningContext;
|
|
45
|
+
private captureSubmission;
|
|
43
46
|
get web3Provider(): CustomJsonRpcProvider;
|
|
44
47
|
private ensureProvidersInitialized;
|
|
45
48
|
private isUtxoNetwork;
|
|
@@ -61,20 +64,17 @@ export declare class EthereumTransactions<TLedger extends EthereumLedgerSigner |
|
|
|
61
64
|
value: any;
|
|
62
65
|
}) => string;
|
|
63
66
|
getFeeDataWithDynamicMaxPriorityFeePerGas: (provider?: CustomJsonRpcProvider) => Promise<{
|
|
64
|
-
gasPrice: BigNumber;
|
|
65
67
|
maxFeePerGas: BigNumber;
|
|
66
68
|
maxPriorityFeePerGas: BigNumber;
|
|
67
|
-
baseFeePerGas?: undefined;
|
|
68
|
-
} | {
|
|
69
|
+
baseFeePerGas?: BigNumber | undefined;
|
|
69
70
|
gasPrice: BigNumber;
|
|
70
|
-
baseFeePerGas: BigNumber;
|
|
71
|
-
maxFeePerGas: BigNumber;
|
|
72
|
-
maxPriorityFeePerGas: BigNumber;
|
|
73
71
|
}>;
|
|
74
72
|
calculateNewGasValues: (oldTxsParams: IGasParams, isForCancel: boolean, isLegacy: boolean) => IGasParams;
|
|
75
73
|
cancelSentTransaction: (txHash: string, isLegacy: boolean | undefined, fallbackNonce: number | undefined, options: IEvmCancellationOptions) => Promise<{
|
|
76
74
|
error?: boolean;
|
|
77
75
|
isCanceled: boolean;
|
|
76
|
+
transactionNotBroadcast?: boolean;
|
|
77
|
+
signedTransactionHash?: string;
|
|
78
78
|
maximumFee?: string;
|
|
79
79
|
transaction?: TransactionResponse;
|
|
80
80
|
}>;
|
|
@@ -84,6 +84,8 @@ export declare class EthereumTransactions<TLedger extends EthereumLedgerSigner |
|
|
|
84
84
|
maximumFee?: string;
|
|
85
85
|
error?: boolean;
|
|
86
86
|
isSpeedUp: boolean;
|
|
87
|
+
transactionNotBroadcast?: boolean;
|
|
88
|
+
signedTransactionHash?: string;
|
|
87
89
|
transaction?: TransactionResponse;
|
|
88
90
|
code?: string;
|
|
89
91
|
message?: string;
|
|
@@ -94,7 +96,7 @@ export declare class EthereumTransactions<TLedger extends EthereumLedgerSigner |
|
|
|
94
96
|
getRecommendedNonce: (address: string) => Promise<number>;
|
|
95
97
|
getFeeByType: (type: string) => Promise<string>;
|
|
96
98
|
getGasLimit: (toAddress: string) => Promise<number>;
|
|
97
|
-
getTxGasLimit: (tx: SimpleTransactionRequest) => Promise<
|
|
99
|
+
getTxGasLimit: (tx: SimpleTransactionRequest) => Promise<BigNumber>;
|
|
98
100
|
getRecommendedGasPrice: (formatted?: boolean) => Promise<string | {
|
|
99
101
|
gwei: string;
|
|
100
102
|
ethers: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ecc from '@bitcoinerlab/secp256k1';
|
|
2
2
|
import { type Deferrable, type TransactionRequest } from '../ethers-v6';
|
|
3
3
|
import { CustomJsonRpcProvider } from '../providers';
|
|
4
|
+
import { type EvmSubmissionBoundary } from './evm-submission';
|
|
4
5
|
export type EvmLocalAccount = {
|
|
5
6
|
address: string;
|
|
6
7
|
privateKey: string;
|
|
@@ -19,8 +20,10 @@ export declare const signDigestHex: (digest: string | Uint8Array, privateKey: st
|
|
|
19
20
|
export declare const hashPersonalMessage: (message: Uint8Array) => string;
|
|
20
21
|
export declare const signPersonalMessage: (message: string | Uint8Array, privateKey: string | Uint8Array) => string;
|
|
21
22
|
export declare const parsePersonalMessage: (hexMessage: string) => string;
|
|
23
|
+
/** Pin the checked gas and chain to the same detached envelope that is serialized. */
|
|
24
|
+
export declare const normalizeGasLimitedTransaction: (transaction: TransactionRequest) => TransactionRequest;
|
|
22
25
|
export declare const signTransaction: (transaction: TransactionRequest, privateKey: string | Uint8Array) => string;
|
|
23
26
|
export declare const sendLocalEvmTransaction: (provider: CustomJsonRpcProvider, privateKey: string, transaction: Deferrable<Record<string, any>>, beforeBroadcast?: () => void, beforeSign?: () => void,
|
|
24
27
|
/** Synchronous final-envelope check; throw to reject. Promise results are rejected. */
|
|
25
|
-
validateBeforeSign?: (transaction: TransactionRequest) => void) => Promise<any>;
|
|
28
|
+
validateBeforeSign?: (transaction: TransactionRequest) => void, submission?: EvmSubmissionBoundary) => Promise<any>;
|
|
26
29
|
export declare const sameAddress: (left: string, right: string) => boolean;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Transaction } from 'ethers/transaction';
|
|
2
|
+
export type EvmSubmissionContext = Readonly<{
|
|
3
|
+
account: Readonly<{
|
|
4
|
+
id: number;
|
|
5
|
+
type: string;
|
|
6
|
+
address: string;
|
|
7
|
+
}>;
|
|
8
|
+
network: Readonly<{
|
|
9
|
+
kind: string;
|
|
10
|
+
chainId: number;
|
|
11
|
+
slip44: number;
|
|
12
|
+
url: string;
|
|
13
|
+
}>;
|
|
14
|
+
operation: 'send' | 'cancel' | 'speed-up' | 'erc20' | 'erc721' | 'erc1155';
|
|
15
|
+
originalHash?: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** Signed wire bytes only; never a key, password or mutable transaction request. */
|
|
18
|
+
export type EvmSignedSubmission = Readonly<{
|
|
19
|
+
context: EvmSubmissionContext;
|
|
20
|
+
rawTransaction: string;
|
|
21
|
+
hash: string;
|
|
22
|
+
from: string;
|
|
23
|
+
chainId: string;
|
|
24
|
+
nonce: number;
|
|
25
|
+
type: number | null;
|
|
26
|
+
}>;
|
|
27
|
+
export type EvmSubmissionLifecycle = Readonly<{
|
|
28
|
+
/** Synchronous host wallet/session/revision check, including A -> B -> A. */
|
|
29
|
+
assertCurrent: () => void;
|
|
30
|
+
/** Resolve only after durable acknowledgement. A rejection never dispatches. */
|
|
31
|
+
persistSigned: (record: EvmSignedSubmission) => Promise<void>;
|
|
32
|
+
}>;
|
|
33
|
+
export type CaptureEvmSubmission = (context: EvmSubmissionContext) => EvmSubmissionLifecycle;
|
|
34
|
+
export type EvmSubmissionBoundary = Readonly<{
|
|
35
|
+
context: EvmSubmissionContext;
|
|
36
|
+
assertCurrent: () => void;
|
|
37
|
+
persistSigned?: (record: EvmSignedSubmission) => Promise<void>;
|
|
38
|
+
}>;
|
|
39
|
+
/** Capture once, before RPC or device work. Never reread host capabilities later. */
|
|
40
|
+
export declare function captureEvmSubmission(input: EvmSubmissionContext, assertCurrent: () => void, capture?: CaptureEvmSubmission): EvmSubmissionBoundary;
|
|
41
|
+
/** Only local stage evidence can label an error as a possibly dispatched send. */
|
|
42
|
+
export declare function evmSubmissionFailure(error: unknown): Readonly<{
|
|
43
|
+
transactionNotBroadcast: boolean;
|
|
44
|
+
signedTransactionHash?: string;
|
|
45
|
+
}>;
|
|
46
|
+
/** Preserve local evidence when an existing public API wraps its Error object. */
|
|
47
|
+
export declare function copyEvmSubmissionFailure(source: unknown, target: Error): void;
|
|
48
|
+
/** Compare signed wire bytes with the complete envelope captured before signing. */
|
|
49
|
+
export declare function assertSignedEvmTransactionMatches(rawTransaction: string, expectedUnsignedTransaction: string, expectedFrom?: string): Transaction;
|
|
50
|
+
/** The sole local-signature dispatch boundary. No nonce/fee selection or retry. */
|
|
51
|
+
export declare function submitSignedEvmTransaction<T>(rawTransaction: string, broadcast: (rawTransaction: string) => Promise<T>, boundary?: EvmSubmissionBoundary, beforeBroadcast?: () => void, expectedUnsignedTransaction?: string): Promise<T>;
|
package/types/types.d.ts
CHANGED
|
@@ -81,6 +81,8 @@ export interface IEthereumTransactions {
|
|
|
81
81
|
cancelSentTransaction: (txHash: string, isLegacy: boolean | undefined, fallbackNonce: number | undefined, options: IEvmCancellationOptions) => Promise<{
|
|
82
82
|
error?: boolean;
|
|
83
83
|
isCanceled: boolean;
|
|
84
|
+
transactionNotBroadcast?: boolean;
|
|
85
|
+
signedTransactionHash?: string;
|
|
84
86
|
maximumFee?: string;
|
|
85
87
|
transaction?: TransactionResponse;
|
|
86
88
|
}>;
|
|
@@ -106,6 +108,8 @@ export interface IEthereumTransactions {
|
|
|
106
108
|
sendTransactionWithEditedFee: (txHash: string, isLegacy?: boolean, options?: IEvmReplacementOptions) => Promise<{
|
|
107
109
|
maximumFee?: string;
|
|
108
110
|
isSpeedUp: boolean;
|
|
111
|
+
transactionNotBroadcast?: boolean;
|
|
112
|
+
signedTransactionHash?: string;
|
|
109
113
|
transaction?: TransactionResponse;
|
|
110
114
|
error?: boolean;
|
|
111
115
|
}>;
|
package/cjs/bip84-native.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepareBip84NativeTransaction = exports.Bip84NativeError = void 0;
|
|
4
|
-
/** Pure native-coin BIP84 transfer preparation, without a wallet or provider. */
|
|
5
|
-
var bip84_native_plan_1 = require("./transactions/bip84-native-plan");
|
|
6
|
-
Object.defineProperty(exports, "Bip84NativeError", { enumerable: true, get: function () { return bip84_native_plan_1.Bip84NativeError; } });
|
|
7
|
-
Object.defineProperty(exports, "prepareBip84NativeTransaction", { enumerable: true, get: function () { return bip84_native_plan_1.prepareBip84NativeTransaction; } });
|
|
8
|
-
//# sourceMappingURL=bip84-native.js.map
|
package/cjs/bip84-native.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bip84-native.js","sourceRoot":"","sources":["../../src/bip84-native.ts"],"names":[],"mappings":";;;AAAA,iFAAiF;AACjF,sEAG0C;AAFxC,qHAAA,gBAAgB,OAAA;AAChB,kIAAA,6BAA6B,OAAA"}
|
package/cjs/public-bip84.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PublicBip84Error = void 0;
|
|
7
|
-
exports.parseBip84PublicAccount = parseBip84PublicAccount;
|
|
8
|
-
exports.deriveBip84PublicAddress = deriveBip84PublicAddress;
|
|
9
|
-
const secp256k1_1 = __importDefault(require("@bitcoinerlab/secp256k1"));
|
|
10
|
-
const bip32_1 = require("bip32");
|
|
11
|
-
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
12
|
-
const bs58check_1 = __importDefault(require("bs58check"));
|
|
13
|
-
class PublicBip84Error extends Error {
|
|
14
|
-
constructor(code) {
|
|
15
|
-
super(code);
|
|
16
|
-
this.code = code;
|
|
17
|
-
this.name = 'PublicBip84Error';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.PublicBip84Error = PublicBip84Error;
|
|
21
|
-
const bip32 = (0, bip32_1.BIP32Factory)(secp256k1_1.default);
|
|
22
|
-
const HARDENED = 0x80000000;
|
|
23
|
-
const XPUB = 0x0488b21e;
|
|
24
|
-
const ZPUB = 0x04b24746;
|
|
25
|
-
// Fixed mainnet encodings, independent of mutable external network objects.
|
|
26
|
-
// These match the Bitcoin/Syscoin registries; no BIP32 node escapes this entry.
|
|
27
|
-
const bitcoin = Object.freeze({
|
|
28
|
-
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
|
29
|
-
bech32: 'bc',
|
|
30
|
-
bip32: Object.freeze({ public: XPUB, private: 0x0488ade4 }),
|
|
31
|
-
pubKeyHash: 0x00,
|
|
32
|
-
scriptHash: 0x05,
|
|
33
|
-
wif: 0x80,
|
|
34
|
-
});
|
|
35
|
-
const syscoin = Object.freeze({
|
|
36
|
-
...bitcoin,
|
|
37
|
-
messagePrefix: '\x18Syscoin Signed Message:\n',
|
|
38
|
-
bech32: 'sys',
|
|
39
|
-
pubKeyHash: 0x3f,
|
|
40
|
-
});
|
|
41
|
-
const addressNetworks = Object.freeze({ bitcoin, syscoin });
|
|
42
|
-
const fail = (code) => {
|
|
43
|
-
throw new PublicBip84Error(code);
|
|
44
|
-
};
|
|
45
|
-
function snapshot(value, keys) {
|
|
46
|
-
try {
|
|
47
|
-
if (!value ||
|
|
48
|
-
typeof value !== 'object' ||
|
|
49
|
-
Array.isArray(value) ||
|
|
50
|
-
![Object.prototype, null].includes(Object.getPrototypeOf(value)) ||
|
|
51
|
-
Reflect.ownKeys(value).length !== keys.length)
|
|
52
|
-
return fail('INVALID_INPUT');
|
|
53
|
-
const result = {};
|
|
54
|
-
for (const key of keys) {
|
|
55
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
56
|
-
if (!descriptor ||
|
|
57
|
-
!descriptor.enumerable ||
|
|
58
|
-
!Object.prototype.hasOwnProperty.call(descriptor, 'value'))
|
|
59
|
-
return fail('INVALID_INPUT');
|
|
60
|
-
result[key] = descriptor.value;
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
return fail('INVALID_INPUT');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function parse(input) {
|
|
69
|
-
if (input.network !== 'bitcoin' && input.network !== 'syscoin')
|
|
70
|
-
return fail('INVALID_INPUT');
|
|
71
|
-
const { accountKey } = input;
|
|
72
|
-
if (typeof accountKey !== 'string' ||
|
|
73
|
-
!/^[1-9A-HJ-NP-Za-km-z]{100,112}$/.test(accountKey))
|
|
74
|
-
return fail('INVALID_ACCOUNT');
|
|
75
|
-
try {
|
|
76
|
-
const payload = Buffer.from(bs58check_1.default.decode(accountKey));
|
|
77
|
-
if (payload.length !== 78 ||
|
|
78
|
-
payload[4] !== 3 ||
|
|
79
|
-
![2, 3].includes(payload[45]))
|
|
80
|
-
return fail('INVALID_ACCOUNT');
|
|
81
|
-
const version = payload.readUInt32BE(0);
|
|
82
|
-
const child = payload.readUInt32BE(9);
|
|
83
|
-
if ((version !== XPUB && version !== ZPUB) || child < HARDENED)
|
|
84
|
-
return fail('INVALID_ACCOUNT');
|
|
85
|
-
const network = addressNetworks[input.network];
|
|
86
|
-
const node = bip32.fromBase58(accountKey, {
|
|
87
|
-
...network,
|
|
88
|
-
bip32: { public: version, private: network.bip32.private },
|
|
89
|
-
});
|
|
90
|
-
if (!node.isNeutered() || node.depth !== 3 || node.index !== child)
|
|
91
|
-
return fail('INVALID_ACCOUNT');
|
|
92
|
-
// Change serialization only after all account/public checks succeeded. No
|
|
93
|
-
// descriptor, coin path or historical purpose can be proven from this key.
|
|
94
|
-
payload.writeUInt32BE(ZPUB, 0);
|
|
95
|
-
const account = Object.freeze({
|
|
96
|
-
network: input.network,
|
|
97
|
-
policy: 'bip84-p2wpkh',
|
|
98
|
-
canonicalKey: bs58check_1.default.encode(payload),
|
|
99
|
-
accountIndex: child - HARDENED,
|
|
100
|
-
});
|
|
101
|
-
return { account, node, network };
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
return fail('INVALID_ACCOUNT');
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Validate one public account and normalize xpub/zpub aliases. The chosen
|
|
109
|
-
* network and BIP84 policy are explicit; ancestry/purpose is not attested.
|
|
110
|
-
* No keyring, storage, provider, randomness or wallet signing is involved.
|
|
111
|
-
* BIP32Factory runs its upstream deterministic ECC self-tests at module load.
|
|
112
|
-
*/
|
|
113
|
-
function parseBip84PublicAccount(request) {
|
|
114
|
-
return parse(snapshot(request, ['network', 'accountKey'])).account;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Derive only /0/index or /1/index from a validated mainnet account key.
|
|
118
|
-
* One bounded input and two child derivations; no discovery, cache or range
|
|
119
|
-
* iteration. Callers own scan limits and privacy consent. Returned data is public.
|
|
120
|
-
*/
|
|
121
|
-
function deriveBip84PublicAddress(request) {
|
|
122
|
-
const input = snapshot(request, ['network', 'accountKey', 'branch', 'index']);
|
|
123
|
-
if ((input.branch !== 0 && input.branch !== 1) ||
|
|
124
|
-
!Number.isInteger(input.index) ||
|
|
125
|
-
input.index < 0 ||
|
|
126
|
-
input.index >= HARDENED)
|
|
127
|
-
return fail('INVALID_INPUT');
|
|
128
|
-
const { account, node, network } = parse(input);
|
|
129
|
-
const branch = input.branch;
|
|
130
|
-
const index = input.index;
|
|
131
|
-
try {
|
|
132
|
-
const branchNode = node.derive(branch);
|
|
133
|
-
if (branchNode.index !== branch)
|
|
134
|
-
return fail('INVALID_DERIVATION');
|
|
135
|
-
const child = branchNode.derive(index);
|
|
136
|
-
// BIP32 implementations can retry an invalid child at index + 1. Such a
|
|
137
|
-
// retry must never silently change the address requested by the caller.
|
|
138
|
-
if (child.index !== index)
|
|
139
|
-
return fail('INVALID_DERIVATION');
|
|
140
|
-
const payment = bitcoinjs_lib_1.payments.p2wpkh({ pubkey: child.publicKey, network });
|
|
141
|
-
if (!payment.address ||
|
|
142
|
-
!payment.output ||
|
|
143
|
-
!Buffer.from(bitcoinjs_lib_1.address.toOutputScript(payment.address, network)).equals(Buffer.from(payment.output)))
|
|
144
|
-
return fail('INVALID_DERIVATION');
|
|
145
|
-
return Object.freeze({
|
|
146
|
-
account,
|
|
147
|
-
branch,
|
|
148
|
-
index,
|
|
149
|
-
address: payment.address,
|
|
150
|
-
scriptPubKey: Buffer.from(payment.output).toString('hex'),
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
catch {
|
|
154
|
-
return fail('INVALID_DERIVATION');
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
//# sourceMappingURL=public-bip84.js.map
|
package/cjs/public-bip84.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"public-bip84.js","sourceRoot":"","sources":["../../src/public-bip84.ts"],"names":[],"mappings":";;;;;;AAqJA,0DAIC;AAOD,4DAwCC;AAxMD,wEAA0C;AAC1C,iCAAqD;AACrD,iDAA6E;AAC7E,0DAAkC;AAyBlC,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YACkB,IAGQ;QAExB,KAAK,CAAC,IAAI,CAAC,CAAC;QALI,SAAI,GAAJ,IAAI,CAGI;QAGxB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAVD,4CAUC;AAED,MAAM,KAAK,GAAG,IAAA,oBAAY,EAAC,mBAAG,CAAC,CAAC;AAChC,MAAM,QAAQ,GAAG,UAAU,CAAC;AAC5B,MAAM,IAAI,GAAG,UAAU,CAAC;AACxB,MAAM,IAAI,GAAG,UAAU,CAAC;AACxB,4EAA4E;AAC5E,gFAAgF;AAChF,MAAM,OAAO,GAAG,MAAM,CAA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AAC,CAAC;QACpC,OAAO,MAAM,CAAC,MAAM,CAAC;YACnB,OAAO;YACP,MAAM;YACN,KAAK;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;SAC1D,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.snapshotBip84HdPublicRequest = snapshotBip84HdPublicRequest;
|
|
4
|
-
const bip84_native_plan_1 = require("./transactions/bip84-native-plan");
|
|
5
|
-
function snapshotBip84HdPublicRequest(value) {
|
|
6
|
-
const r = (0, bip84_native_plan_1.record)(value, ['network', 'accountIndex']);
|
|
7
|
-
return Object.freeze({
|
|
8
|
-
network: (0, bip84_native_plan_1.snapshotBip84Network)(r.network),
|
|
9
|
-
accountIndex: (0, bip84_native_plan_1.index)(r.accountIndex),
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=software-utxo-account.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"software-utxo-account.js","sourceRoot":"","sources":["../../src/software-utxo-account.ts"],"names":[],"mappings":";;AAkBA,oEAQC;AAzBD,wEAK0C;AAY1C,SAAgB,4BAA4B,CAC1C,KAAc;IAEd,MAAM,CAAC,GAAG,IAAA,0BAAM,EAAC,KAAK,EAAE,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,IAAA,wCAAoB,EAAC,CAAC,CAAC,OAAO,CAAC;QACxC,YAAY,EAAE,IAAA,yBAAK,EAAC,CAAC,CAAC,YAAY,CAAC;KACpC,CAAC,CAAC;AACL,CAAC"}
|