@sidhujag/sysweb3-keyring 1.0.619 → 1.0.621

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.
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertNoExcludedInputs = exports.filterExcludedUtxos = exports.excludedOutpointIds = void 0;
4
+ const invalid = () => Object.assign(new Error('Invalid protected UTXO selection.'), {
5
+ error: true,
6
+ code: 'INVALID_EXCLUDED_UTXOS',
7
+ });
8
+ const excludedOutpointIds = (outpoints = []) => {
9
+ if (!Array.isArray(outpoints) || outpoints.length > 1000)
10
+ throw invalid();
11
+ return new Set(outpoints.map((entry) => {
12
+ if (!entry ||
13
+ typeof entry.txid !== 'string' ||
14
+ !/^[0-9a-fA-F]{64}$/.test(entry.txid) ||
15
+ !Number.isSafeInteger(entry.vout) ||
16
+ entry.vout < 0 ||
17
+ entry.vout > 0xffffffff)
18
+ throw invalid();
19
+ return `${entry.txid.toLowerCase()}:${entry.vout}`;
20
+ }));
21
+ };
22
+ exports.excludedOutpointIds = excludedOutpointIds;
23
+ /** Preserve the backend's asset metadata while removing only reserved outputs. */
24
+ const filterExcludedUtxos = (raw, excluded) => {
25
+ const rows = Array.isArray(raw) ? raw : raw?.utxos;
26
+ if (!Array.isArray(rows))
27
+ throw invalid();
28
+ const utxos = rows.filter((row) => {
29
+ const txid = row?.txId ?? row?.txid;
30
+ if (typeof txid !== 'string' ||
31
+ !/^[0-9a-fA-F]{64}$/.test(txid) ||
32
+ !Number.isSafeInteger(row.vout) ||
33
+ row.vout < 0 ||
34
+ row.vout > 0xffffffff ||
35
+ (row.txId !== undefined &&
36
+ row.txid !== undefined &&
37
+ (typeof row.txId !== 'string' ||
38
+ typeof row.txid !== 'string' ||
39
+ row.txId.toLowerCase() !== row.txid.toLowerCase())))
40
+ throw invalid();
41
+ return !excluded.has(`${txid.toLowerCase()}:${row.vout}`);
42
+ });
43
+ return Array.isArray(raw) ? { utxos } : { ...raw, utxos };
44
+ };
45
+ exports.filterExcludedUtxos = filterExcludedUtxos;
46
+ const assertNoExcludedInputs = (psbt, excluded) => {
47
+ if (!Array.isArray(psbt?.txInputs))
48
+ throw invalid();
49
+ for (const input of psbt.txInputs) {
50
+ const id = `${Buffer.from(input.hash).reverse().toString('hex')}:${input.index}`;
51
+ if (excluded.has(id))
52
+ throw Object.assign(new Error('This transaction would spend protected collateral.'), {
53
+ error: true,
54
+ code: 'PROTECTED_COLLATERAL',
55
+ });
56
+ }
57
+ };
58
+ exports.assertNoExcludedInputs = assertNoExcludedInputs;
59
+ //# sourceMappingURL=excluded-utxos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excluded-utxos.js","sourceRoot":"","sources":["../../../src/utils/excluded-utxos.ts"],"names":[],"mappings":";;;AAKA,MAAM,OAAO,GAAG,GAAG,EAAE,CACnB,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,EAAE;IAC5D,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,wBAAwB;CAC/B,CAAC,CAAC;AAEE,MAAM,mBAAmB,GAAG,CACjC,YAAyC,EAAE,EAC9B,EAAE;IACf,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,IAAI;QAAE,MAAM,OAAO,EAAE,CAAC;IAC1E,OAAO,IAAI,GAAG,CACZ,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IACE,CAAC,KAAK;YACN,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;YAC9B,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACrC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;YACjC,KAAK,CAAC,IAAI,GAAG,CAAC;YACd,KAAK,CAAC,IAAI,GAAG,UAAU;YAEvB,MAAM,OAAO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AC,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC;AAC5D,CAAC,CAAC;AAxBW,QAAA,mBAAmB,uBAwB9B;AAEK,MAAM,sBAAsB,GAAG,CACpC,IAAyD,EACzD,QAA6B,EAC7B,EAAE;IACF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;QAAE,MAAM,OAAO,EAAE,CAAC;IACpD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClC,MAAM,EAAE,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAC7D,KAAK,CAAC,KACR,EAAE,CAAC;QACH,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,MAAM,CAAC,MAAM,CACjB,IAAI,KAAK,CAAC,oDAAoD,CAAC,EAC/D;gBACE,KAAK,EAAE,IAAI;gBACX,IAAI,EAAE,sBAAsB;aAC7B,CACF,CAAC;IACN,CAAC;AACH,CAAC,CAAC;AAlBW,QAAA,sBAAsB,0BAkBjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sidhujag/sysweb3-keyring",
3
- "version": "1.0.619",
3
+ "version": "1.0.621",
4
4
  "description": "Keyring Manager for UTXO and Web3 Wallets",
5
5
  "main": "cjs/index.js",
6
6
  "types": "types/index.d.ts",
@@ -79,7 +79,7 @@ export declare class KeyringManager implements IKeyringManager {
79
79
  private isDescriptor;
80
80
  private isXpubLike;
81
81
  private isWatchOnlyAccount;
82
- getEncryptedXprv: (hd: SyscoinHDSigner) => any;
82
+ getEncryptedXprv: (hd: SyscoinHDSigner) => string;
83
83
  getSeed: (pwd: string) => Promise<any>;
84
84
  deriveSLHDSASetupSecretForAccount: ({ accountIndex, }: {
85
85
  accountIndex: number;
@@ -11,6 +11,7 @@ export declare class EthereumTransactions implements IEthereumTransactions {
11
11
  trezorSigner: TrezorKeyring;
12
12
  ledgerSigner: LedgerKeyring;
13
13
  private getNetwork;
14
+ private captureSigningContext?;
14
15
  private abortController;
15
16
  private getDecryptedPrivateKey;
16
17
  private gasOverrides;
@@ -28,7 +29,8 @@ export declare class EthereumTransactions implements IEthereumTransactions {
28
29
  activeAccountId: number;
29
30
  activeAccountType: KeyringAccountType;
30
31
  activeNetwork: INetwork;
31
- }, ledgerSigner: LedgerKeyring, trezorSigner: TrezorKeyring);
32
+ }, ledgerSigner: LedgerKeyring, trezorSigner: TrezorKeyring, captureSigningContext?: () => () => void);
33
+ private captureEvmSigningContext;
32
34
  get web3Provider(): CustomJsonRpcProvider;
33
35
  private ensureProvidersInitialized;
34
36
  private isUtxoNetwork;
@@ -4,6 +4,7 @@ import { LedgerKeyring } from '../ledger';
4
4
  import { SyscoinHDSigner } from '../signers';
5
5
  import { TrezorKeyring } from '../trezor';
6
6
  import { ISyscoinTransactions, KeyringAccountType, accountType } from '../types';
7
+ import { ExcludedOutpoint } from '../utils/excluded-utxos';
7
8
  export declare class SyscoinTransactions implements ISyscoinTransactions {
8
9
  private getSigner;
9
10
  private getReadOnlySigner;
@@ -39,7 +40,7 @@ export declare class SyscoinTransactions implements ISyscoinTransactions {
39
40
  private createNativeSweepPSBT;
40
41
  private createUnsignedPSBT;
41
42
  private signPSBTWithMethod;
42
- getEstimateSysTransactionFee: ({ txOptions, isMax, nativeSweep, amount, receivingAddress, feeRate, token, }: {
43
+ getEstimateSysTransactionFee: ({ txOptions, isMax, nativeSweep, amount, receivingAddress, feeRate, token, excludedOutpoints, }: {
43
44
  amount: number | string;
44
45
  feeRate?: number;
45
46
  receivingAddress: string;
@@ -50,6 +51,7 @@ export declare class SyscoinTransactions implements ISyscoinTransactions {
50
51
  txOptions?: any;
51
52
  isMax?: boolean | false;
52
53
  nativeSweep?: boolean;
54
+ excludedOutpoints?: readonly ExcludedOutpoint[];
53
55
  }) => Promise<{
54
56
  grossAmount?: string | undefined;
55
57
  recipientAmount?: string | undefined;
package/types/types.d.ts CHANGED
@@ -99,7 +99,7 @@ export interface ISyscoinTransactionFeeQuote {
99
99
  recipientAmount?: string;
100
100
  }
101
101
  export interface ISyscoinTransactions {
102
- getEstimateSysTransactionFee: ({ txOptions, amount, receivingAddress, feeRate, token, isMax, nativeSweep, }: {
102
+ getEstimateSysTransactionFee: ({ txOptions, amount, receivingAddress, feeRate, token, isMax, nativeSweep, excludedOutpoints, }: {
103
103
  amount: number | string;
104
104
  feeRate?: number;
105
105
  receivingAddress: string;
@@ -111,6 +111,11 @@ export interface ISyscoinTransactions {
111
111
  isMax?: boolean | false;
112
112
  /** Resolve explicit native MAX from one current funding snapshot. Requires isMax and token:null. */
113
113
  nativeSweep?: boolean;
114
+ /** Coin-control exclusions supplied by a trusted wallet policy, not transaction outputs. */
115
+ excludedOutpoints?: readonly {
116
+ txid: string;
117
+ vout: number;
118
+ }[];
114
119
  }) => Promise<ISyscoinTransactionFeeQuote>;
115
120
  getRecommendedFee: (explorerUrl: string) => Promise<number>;
116
121
  decodeRawTransaction: (psbtOrHex: any, isRawHex?: boolean) => any;
@@ -0,0 +1,13 @@
1
+ export interface ExcludedOutpoint {
2
+ txid: string;
3
+ vout: number;
4
+ }
5
+ export declare const excludedOutpointIds: (outpoints?: readonly ExcludedOutpoint[]) => Set<string>;
6
+ /** Preserve the backend's asset metadata while removing only reserved outputs. */
7
+ export declare const filterExcludedUtxos: (raw: any, excluded: ReadonlySet<string>) => any;
8
+ export declare const assertNoExcludedInputs: (psbt: {
9
+ txInputs: {
10
+ hash: Uint8Array;
11
+ index: number;
12
+ }[];
13
+ }, excluded: ReadonlySet<string>) => void;