@knuth/js-wasm 2.11.0 → 4.0.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.
Files changed (79) hide show
  1. package/LICENSE.md +23 -0
  2. package/README.md +119 -27
  3. package/SHA256SUMS +4 -0
  4. package/package.json +21 -8
  5. package/src/browser_headers_persistent_v1.js +2 -0
  6. package/src/browser_headers_persistent_v1.wasm +0 -0
  7. package/src/kth.js +6 -3
  8. package/src/kth.wasm +0 -0
  9. package/types/AsyncResults.d.ts +11 -0
  10. package/types/Bitcoin.d.ts +4 -0
  11. package/types/DerivationPath.d.ts +8 -0
  12. package/types/DoubleList.d.ts +5 -4
  13. package/types/EcCompressed.d.ts +8 -3
  14. package/types/EcPublic.d.ts +10 -4
  15. package/types/ElectrumClient.d.ts +79 -0
  16. package/types/EllipticCurve.d.ts +8 -2
  17. package/types/Hash.d.ts +5 -0
  18. package/types/HdPublic.d.ts +9 -3
  19. package/types/Input.d.ts +10 -7
  20. package/types/InputList.d.ts +6 -5
  21. package/types/Interpreter.d.ts +9 -1
  22. package/types/Kth.d.ts +4 -0
  23. package/types/LazySequence.d.ts +4 -0
  24. package/types/ListHelper.d.ts +13 -1
  25. package/types/ListNative.d.ts +4 -0
  26. package/types/NativeLifetime.d.ts +11 -0
  27. package/types/Opcode.d.ts +10 -3
  28. package/types/OpcodeAliases.d.ts +16 -0
  29. package/types/Operation.d.ts +31 -26
  30. package/types/OperationList.d.ts +6 -5
  31. package/types/Output.d.ts +11 -7
  32. package/types/OutputList.d.ts +6 -5
  33. package/types/OutputPoint.d.ts +8 -4
  34. package/types/PaymentAddress.d.ts +15 -10
  35. package/types/PaymentAddressList.d.ts +6 -5
  36. package/types/Program.d.ts +15 -2
  37. package/types/RuleFork.d.ts +4 -0
  38. package/types/Script.d.ts +34 -19
  39. package/types/ScriptFlags.d.ts +67 -0
  40. package/types/Secret.d.ts +4 -0
  41. package/types/SecretFunctions.d.ts +4 -0
  42. package/types/SighashAlgorithm.d.ts +4 -0
  43. package/types/SighashGuard.d.ts +10 -0
  44. package/types/StringList.d.ts +5 -4
  45. package/types/TokenData.d.ts +8 -3
  46. package/types/TokenDataBothKinds.d.ts +6 -3
  47. package/types/TokenDataFungible.d.ts +4 -0
  48. package/types/TokenDataNonFungible.d.ts +9 -2
  49. package/types/Transaction.d.ts +12 -10
  50. package/types/TransactionHelpers.d.ts +14 -0
  51. package/types/U32List.d.ts +5 -4
  52. package/types/U64List.d.ts +5 -4
  53. package/types/Utxo.d.ts +10 -6
  54. package/types/UtxoList.d.ts +6 -5
  55. package/types/Wallet.d.ts +28 -52
  56. package/types/WalletData.d.ts +5 -1
  57. package/types/WalletManager.d.ts +6 -3
  58. package/types/WalletUtils.d.ts +53 -0
  59. package/types/encoding.d.ts +4 -0
  60. package/types/env.d.ts +4 -0
  61. package/types/logger.d.ts +6 -0
  62. package/types/main.d.ts +75 -2
  63. package/types/nativeScope.d.ts +11 -0
  64. package/types/types.d.ts +4 -0
  65. package/types/utils.d.ts +4 -0
  66. package/types/wasm/EmscriptenModule.d.ts +4 -0
  67. package/types/wasm/bootloader.d.ts +4 -0
  68. package/types/wasm/callbacks.d.ts +30 -0
  69. package/types/wasm/exceptions.d.ts +4 -0
  70. package/types/wasm/glue.d.ts +960 -170
  71. package/types/wasm/glue_manual.d.ts +4 -0
  72. package/types/wasm/loadLib.d.ts +4 -0
  73. package/types/wasm/manualGeneratedTypes.d.ts +4 -0
  74. package/types/wasm/mem.d.ts +33 -1
  75. package/types/wasm/promises.d.ts +4 -0
  76. package/types/wasm/stack.d.ts +6 -0
  77. package/types/wasm/string.d.ts +13 -0
  78. package/types/LazySequence copy.d.ts +0 -0
  79. package/types/wasm/glue copy.d.ts +0 -230
@@ -1,11 +1,24 @@
1
- import { ProgramNative } from './wasm/glue';
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
2
5
  import { Script } from './Script';
3
6
  import { Transaction } from './Transaction';
7
+ import { ProgramNative } from './wasm/glue';
8
+ export declare const UNKNOWN_SPENT_VALUE = 18446744073709551615n;
4
9
  export declare class Program {
5
10
  private native;
11
+ private ownsNative;
12
+ private readonly lifetime;
13
+ private disposed;
14
+ constructor(script?: Script, programOrTransaction?: Program | Transaction, inputIndex?: number, flags?: bigint, value?: bigint);
15
+ constructor(script?: Script, programOrTransaction?: Program | Transaction);
6
16
  constructor(native: ProgramNative);
7
- constructor(script?: Script, programOrTransaction?: Program | Transaction, inputIndex?: number, forks?: number);
17
+ static adopt(native: ProgramNative, dependsOn?: Array<Program>): Program;
18
+ private live;
19
+ dispose(): void;
8
20
  toNative(): ProgramNative;
21
+ copy(): Program;
9
22
  get valid(): boolean;
10
23
  evaluate(): number;
11
24
  stackResult(clean: boolean): boolean;
@@ -1,3 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  export declare class RuleFork {
2
6
  static forkMinYear: number;
3
7
  static forkMaxYear: number;
package/types/Script.d.ts CHANGED
@@ -1,27 +1,41 @@
1
- import { ScriptNative, EndorsementType } from './wasm/glue';
2
- import { Operation } from './Operation';
3
- import { Transaction } from './Transaction';
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
4
5
  import { ShortHash } from './Hash';
6
+ import { Operation } from './Operation';
5
7
  import { EcSecret } from './Secret';
8
+ import { Transaction } from './Transaction';
9
+ import { EndorsementType, ScriptNative, ScriptPattern } from './wasm/glue';
10
+ export type EndorsementResult = {
11
+ success: true;
12
+ errorCode: 0;
13
+ data: Uint8Array;
14
+ } | {
15
+ success: false;
16
+ errorCode: number;
17
+ };
18
+ export declare class EndorsementError extends Error {
19
+ readonly errorCode: number;
20
+ constructor(errorCode: number);
21
+ }
6
22
  export declare class Script {
7
23
  private encoded;
8
24
  private prefix;
9
25
  static fromNative(native: ScriptNative, destroy?: boolean): Script;
26
+ constructor(encoded: Uint8Array, prefix: boolean);
27
+ toNative(): ScriptNative;
10
28
  static fromData(encoded: Uint8Array, prefix: boolean): Script | undefined;
11
29
  static fromString(str: string): Script | undefined;
12
30
  static fromOperations(operations: Array<Operation>): Script | undefined;
13
31
  static isValid(encoded: Uint8Array, prefix: boolean): boolean;
14
- constructor(encoded: Uint8Array, prefix: boolean);
15
- toNative(): ScriptNative;
16
32
  get valid(): boolean;
17
33
  get isValidOperations(): boolean;
18
- get satoshiContentSize(): number;
19
34
  get serializedSize(): number;
20
- get type(): string;
21
- get operations(): Operation[];
22
- toString(activeForks: number): string;
23
- toData(prefix: boolean): Uint8Array<ArrayBufferLike>;
24
- toBytes(): Uint8Array<ArrayBufferLike>;
35
+ get operations(): Array<Operation>;
36
+ toString(activeFlags: bigint): string;
37
+ toData(prefix: boolean): Uint8Array;
38
+ toBytes(): Uint8Array;
25
39
  static isPushOnly(ops: Array<Operation>): boolean;
26
40
  static isRelaxedPush(ops: Array<Operation>): boolean;
27
41
  static isCoinbasePattern(ops: Array<Operation>, height: number): boolean;
@@ -33,19 +47,20 @@ export declare class Script {
33
47
  static isSignPublicKeyPattern(ops: Array<Operation>): boolean;
34
48
  static isSignPublicKeyHashPattern(ops: Array<Operation>): boolean;
35
49
  static isSignScriptHashPattern(ops: Array<Operation>): boolean;
36
- static toNullDataPattern(data: Uint8Array): Array<Operation>;
37
- static toPayPublicKeyPattern(point: Uint8Array): Array<Operation>;
50
+ static toNullDataPattern(data: Uint8Array): Array<Operation> | undefined;
51
+ static toPayPublicKeyPattern(point: Uint8Array): Array<Operation> | undefined;
38
52
  static toPayPublicKeyHashPattern(hash: ShortHash): Array<Operation>;
39
53
  static toPayScriptHashPattern(hash: ShortHash): Array<Operation>;
40
- pattern(): "null_data" | "pay_multisig" | "pay_public_key" | "pay_public_key_hash" | "pay_script_hash" | "sign_multisig" | "sign_public_key" | "sign_public_key_hash" | "sign_script_hash" | "witness_reservation" | "non_standard";
41
- outputPattern(): "null_data" | "pay_multisig" | "pay_public_key" | "pay_public_key_hash" | "pay_script_hash" | "sign_multisig" | "sign_public_key" | "sign_public_key_hash" | "sign_script_hash" | "witness_reservation" | "non_standard";
42
- inputPattern(): "null_data" | "pay_multisig" | "pay_public_key" | "pay_public_key_hash" | "pay_script_hash" | "sign_multisig" | "sign_public_key" | "sign_public_key_hash" | "sign_script_hash" | "witness_reservation" | "non_standard";
54
+ pattern(): ScriptPattern;
55
+ outputPattern(): ScriptPattern;
56
+ inputPattern(): ScriptPattern;
43
57
  get sigops(): number;
44
58
  get sigopsAccurate(): number;
45
59
  get isUnspendable(): boolean;
46
60
  reset(): void;
47
- static createEndorsement(secret: EcSecret, prevoutScript: Script, tx: Transaction, inputIndex: number, sighashType: number, activeForks: number, value: bigint, endorsementType: EndorsementType): Uint8Array;
48
- static verify(tx: Transaction, input: number, forks: number, inputScript: Script, prevoutScript: Script, value: bigint): number;
49
- static verifyTransaction(tx: Transaction, input: number, forks: number): number;
61
+ static createEndorsementResult(secret: EcSecret, prevoutScript: Script, tx: Transaction, inputIndex: number, sighashType: number, activeFlags: bigint, value: bigint, endorsementType: EndorsementType): EndorsementResult;
62
+ static createEndorsement(secret: EcSecret, prevoutScript: Script, tx: Transaction, inputIndex: number, sighashType: number, activeFlags: bigint, value: bigint, endorsementType: EndorsementType): Uint8Array;
63
+ static verify(tx: Transaction, input: number, flags: bigint, inputScript: Script, prevoutScript: Script, value: bigint): number;
64
+ static verifyTransaction(tx: Transaction, input: number, flags: bigint): number;
50
65
  }
51
66
  export default Script;
@@ -0,0 +1,67 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ export declare const ScriptFlags: Readonly<{
6
+ noRules: 0n;
7
+ easyBlocks: 1n;
8
+ bip16Rule: 2n;
9
+ bip30Rule: 4n;
10
+ bip34Rule: 8n;
11
+ bip66Rule: 16n;
12
+ bip65Rule: 32n;
13
+ bip90Rule: 64n;
14
+ allowCollisions: 128n;
15
+ bip68Rule: 256n;
16
+ bip112Rule: 512n;
17
+ bip113Rule: 1024n;
18
+ bchStrictenc: 2048n;
19
+ bchSighashForkid: 4096n;
20
+ bchLowS: 8192n;
21
+ bchNullfail: 16384n;
22
+ bchReactivatedOpcodes: 32768n;
23
+ bchSigpushonly: 65536n;
24
+ bchCleanstack: 131072n;
25
+ bchSchnorrMultisig: 262144n;
26
+ bchMinimaldata: 524288n;
27
+ bchEnforceSigchecks: 1048576n;
28
+ bch64bitIntegers: 2097152n;
29
+ bchNativeIntrospection: 4194304n;
30
+ bchP2sh32: 8388608n;
31
+ bchTokens: 16777216n;
32
+ bchVmLimits: 33554432n;
33
+ bchBigint: 67108864n;
34
+ bchLoops: 134217728n;
35
+ bchSubroutines: 268435456n;
36
+ bchBitwiseOps: 536870912n;
37
+ bchP2s: 1073741824n;
38
+ bch2027May: 2147483648n;
39
+ bchVmLimitsStandard: 144115188075855872n;
40
+ bchMinimalif: 288230376151711744n;
41
+ bchInputSigchecks: 576460752303423488n;
42
+ bchDiscourageUpgradableNops: 1152921504606846976n;
43
+ bchDisallowSegwitRecovery: 2305843009213693952n;
44
+ retarget: 4611686018427387904n;
45
+ unverified: 9223372036854775808n;
46
+ allPolicyFlags: 4467570830351532032n;
47
+ allRules: 144115188075855871n;
48
+ allBits: 18446744073709551615n;
49
+ standardPolicyFlags: 4467570830351532032n;
50
+ }>;
51
+ export declare const ScriptUpgrades: Readonly<{
52
+ bip34Activations: 56n;
53
+ bchUahf: 6144n;
54
+ bchDaaCw144: 30720n;
55
+ bchPythagoras: 63488n;
56
+ bchEuclid: 260096n;
57
+ bchPisano: 260096n;
58
+ bchMersenne: 1046528n;
59
+ bchFermat: 2095104n;
60
+ bchEuler: 2095104n;
61
+ bchGauss: 8386560n;
62
+ bchDescartes: 33552384n;
63
+ bchLobachevski: 33552384n;
64
+ bchGalois: 134215680n;
65
+ bchLeibniz: 2147481600n;
66
+ bchCantor: 4294965248n;
67
+ }>;
package/types/Secret.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  export type EcSecret = Uint8Array & {
2
6
  length: 32;
3
7
  };
@@ -1,3 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  import { EcSecretNative } from './wasm/glue';
2
6
  import { EcSecret } from './Secret';
3
7
  export declare class SecretFunctions {
@@ -1,3 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  export declare class SighashAlgorithm {
2
6
  static all: number;
3
7
  static none: number;
@@ -0,0 +1,10 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ import type { Transaction } from './Transaction';
6
+ export type SighashRefusal = {
7
+ success: false;
8
+ errorCode: number;
9
+ };
10
+ export declare function refuseSighashUtxos(tx: Transaction, sighashType: number, activeFlags: bigint): SighashRefusal | undefined;
@@ -1,6 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  import { StringListNative } from './wasm/glue';
2
- export declare class StringList {
3
- static fromNative(native: StringListNative): Array<string>;
4
- static toNative(strings: Array<string>): StringListNative;
5
- }
6
+ export declare const StringList: import("./ListHelper").ListAdapter<string, StringListNative>;
6
7
  export default StringList;
@@ -1,8 +1,12 @@
1
- import { TokenDataNative } from './wasm/glue';
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
2
5
  import { Hash } from './Hash';
6
+ import { TokenDataBothKinds } from './TokenDataBothKinds';
3
7
  import { TokenDataFungible } from './TokenDataFungible';
4
8
  import { TokenDataNonFungible } from './TokenDataNonFungible';
5
- import { TokenDataBothKinds } from './TokenDataBothKinds';
9
+ import { TokenDataNative } from './wasm/glue';
6
10
  export type TokenDataInternal = TokenDataFungible | TokenDataNonFungible | TokenDataBothKinds;
7
11
  export declare class TokenData {
8
12
  category?: Hash;
@@ -11,8 +15,9 @@ export declare class TokenData {
11
15
  constructor(category?: Hash, data?: TokenDataInternal);
12
16
  get valid(): boolean;
13
17
  get kind(): 'fungible' | 'non_fungible' | 'both' | undefined;
18
+ private tryToNative;
14
19
  toNative(): TokenDataNative;
15
20
  serializedSize(): number;
16
- toData(): Uint8Array<ArrayBufferLike>;
21
+ toData(): Uint8Array;
17
22
  }
18
23
  export default TokenData;
@@ -1,9 +1,12 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  import { TokenDataFungible } from './TokenDataFungible';
2
- import { TokenDataNonFungible } from './TokenDataNonFungible';
3
- import { TokenCapability } from './wasm/glue';
6
+ import { TokenCapabilityName, TokenDataNonFungible } from './TokenDataNonFungible';
4
7
  export declare class TokenDataBothKinds {
5
8
  fungible: TokenDataFungible;
6
9
  nonFungible: TokenDataNonFungible;
7
- constructor(amount: bigint, capability: TokenCapability, commitment: Uint8Array);
10
+ constructor(amount: bigint, capability: TokenCapabilityName, commitment: Uint8Array);
8
11
  }
9
12
  export default TokenDataBothKinds;
@@ -1,3 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  export declare class TokenDataFungible {
2
6
  amount: bigint;
3
7
  constructor(amount: bigint);
@@ -1,7 +1,14 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  import { TokenCapability } from './wasm/glue';
6
+ export type TokenCapabilityName = 'none' | 'mutable' | 'minting';
7
+ export declare function capabilityToNative(value: TokenCapabilityName): TokenCapability;
8
+ export declare function capabilityFromNative(value: TokenCapability): TokenCapabilityName;
2
9
  export declare class TokenDataNonFungible {
3
- capability: TokenCapability;
10
+ capability: TokenCapabilityName;
4
11
  commitment: Uint8Array;
5
- constructor(capability: TokenCapability, commitment: Uint8Array);
12
+ constructor(capability: TokenCapabilityName, commitment: Uint8Array);
6
13
  }
7
14
  export default TokenDataNonFungible;
@@ -1,30 +1,32 @@
1
- import { TransactionNative, CoinSelectionAlgorithm } from './wasm/glue';
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
2
5
  import { Hash } from './Hash';
3
6
  import { Input } from './Input';
4
7
  import { Output } from './Output';
5
- import { PaymentAddress } from './PaymentAddress';
6
- import { Utxo } from './Utxo';
8
+ import { TransactionNative } from './wasm/glue';
7
9
  export declare class Transaction {
8
10
  version?: number;
9
11
  locktime?: number;
10
12
  inputs?: Array<Input>;
11
13
  outputs?: Array<Output>;
12
14
  static fromNative(native: TransactionNative, destroy?: boolean): Transaction;
13
- static fromData(data: Uint8Array): Transaction | undefined;
14
- static isValid(data: Uint8Array): boolean;
15
15
  constructor(version?: number, locktime?: number, inputs?: Array<Input>, outputs?: Array<Output>);
16
- get valid(): boolean;
17
16
  toNative(): TransactionNative;
18
- serializedSize(wire: boolean): number;
19
- toData(wire: boolean): Uint8Array<ArrayBufferLike>;
17
+ get valid(): boolean;
18
+ serializedSize(wire?: boolean): number;
19
+ toData(wire: boolean): Uint8Array;
20
+ private static decode;
21
+ static fromData(data: Uint8Array): Transaction | undefined;
22
+ static isValid(data: Uint8Array): boolean;
20
23
  clone(): Transaction | undefined;
24
+ static hasSameSigningStructure(template: Transaction, signed: Transaction): boolean;
21
25
  get hash(): Hash;
22
26
  get isCoinbase(): boolean;
23
27
  get totalInputValue(): bigint;
24
28
  get totalOutputValue(): bigint;
25
29
  get fees(): bigint;
26
30
  isMature(targetHeight: number): boolean;
27
- static createTemplateWithChangeRatios(availableUtxos: Array<Utxo>, amountToSend: bigint, destinationAddress: PaymentAddress, changeAddresses: Array<PaymentAddress>, changeRatios: Array<number>, selectionAlgo: CoinSelectionAlgorithm): [number, Transaction | undefined, Array<number> | undefined, Array<PaymentAddress> | undefined, Array<bigint> | undefined];
28
- static createTemplate(availableUtxos: Array<Utxo>, amountToSend: bigint, destinationAddress: PaymentAddress, changeAddresses: Array<PaymentAddress>, selectionAlgo: CoinSelectionAlgorithm): [number, Transaction | undefined, Array<number> | undefined, Array<PaymentAddress> | undefined, Array<bigint> | undefined];
29
31
  }
30
32
  export default Transaction;
@@ -0,0 +1,14 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ import { Transaction } from './Transaction';
6
+ export declare function cloneTransaction(transaction: Transaction): Transaction | undefined;
7
+ /**
8
+ * Validate that a wallet response only changed input unlocking scripts.
9
+ *
10
+ * Wallets are allowed to populate each input script while signing, but they
11
+ * must not change the transaction version, locktime, input outpoints,
12
+ * sequences, outputs, BCH amounts, locking bytecode, or token data.
13
+ */
14
+ export declare function hasSameSigningStructure(template: Transaction, signed: Transaction): boolean;
@@ -1,6 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  import { U32ListNative } from './wasm/glue';
2
- export declare class U32List {
3
- static fromNative(native: U32ListNative): Array<number>;
4
- static toNative(numbers: Array<number>): U32ListNative;
5
- }
6
+ export declare const U32List: import("./ListHelper").ListAdapter<number, U32ListNative>;
6
7
  export default U32List;
@@ -1,6 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  import { U64ListNative } from './wasm/glue';
2
- export declare class U64List {
3
- static fromNative(native: U64ListNative): Array<bigint>;
4
- static toNative(numbers: Array<bigint>): U64ListNative;
5
- }
6
+ export declare const U64List: import("./ListHelper").ListAdapter<bigint, U64ListNative>;
6
7
  export default U64List;
package/types/Utxo.d.ts CHANGED
@@ -1,17 +1,21 @@
1
- import { UtxoNative } from './wasm/glue';
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
2
5
  import { Hash } from './Hash';
3
- import Output from './Output';
4
- import TokenData from './TokenData';
6
+ import { Output } from './Output';
7
+ import { TokenData } from './TokenData';
8
+ import { UtxoNative } from './wasm/glue';
5
9
  export declare class Utxo {
6
10
  hash?: Hash;
7
11
  index?: number;
8
12
  amount?: bigint;
9
- cachedOutput?: Output;
10
13
  tokenData?: TokenData;
14
+ cachedOutput?: Output;
11
15
  static fromNative(native: UtxoNative, destroy?: boolean): Utxo;
12
- static isValid(hash: Hash, index: number, amount: bigint): boolean;
13
16
  constructor(hash?: Hash, index?: number, amount?: bigint, tokenData?: TokenData);
14
- get valid(): boolean;
15
17
  toNative(): UtxoNative;
18
+ static isValid(hash: Hash, index: number, amount: bigint): boolean;
19
+ get valid(): boolean;
16
20
  }
17
21
  export default Utxo;
@@ -1,7 +1,8 @@
1
- import { UtxoListNative } from './wasm/glue';
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
2
5
  import { Utxo } from './Utxo';
3
- export declare class UtxoList {
4
- static fromNative(native: UtxoListNative): Array<Utxo>;
5
- static toNative(utxos: Array<Utxo>): UtxoListNative;
6
- }
6
+ import { UtxoListNative } from './wasm/glue';
7
+ export declare const UtxoList: import("./ListHelper").ListAdapter<Utxo, UtxoListNative>;
7
8
  export default UtxoList;
package/types/Wallet.d.ts CHANGED
@@ -1,62 +1,38 @@
1
- import { PaymentAddress } from './PaymentAddress';
2
- import { EcSecret } from './Secret';
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
3
5
  import { EcPublic } from './EcPublic';
4
6
  import { LongHash } from './Hash';
7
+ import { PaymentAddress } from './PaymentAddress';
8
+ import { EcSecret } from './Secret';
9
+ export type WalletTriple = {
10
+ secret: EcSecret;
11
+ publicKey: EcPublic;
12
+ address: PaymentAddress;
13
+ };
5
14
  export declare class Wallet {
6
- private mnemonic;
7
- private derivationPath;
8
- private network;
9
- private seed;
15
+ private readonly mnemonic;
16
+ private readonly derivationPath;
17
+ private readonly network;
18
+ private readonly seed;
10
19
  private master;
11
- private lastDerived;
12
- /**
13
- * Create a Wallet from a BIP39 mnemonic phrase (recommended factory method)
14
- * @param mnemonic - Array of BIP39 words (12, 15, 18, 21, or 24 words)
15
- * @param derivationPath - BIP32/BIP44 derivation path (e.g., "m/44'/145'/0'/0")
16
- * @param network - Network type: 'MAINNET' or 'TESTNET'
17
- * @returns New Wallet instance
18
- * @example
19
- * const wallet = Wallet.fromMnemonic(
20
- * ['word1', 'word2', ...],
21
- * "m/44'/145'/0'/0",
22
- * 'MAINNET'
23
- * );
24
- */
25
- static fromMnemonic(mnemonic: string[], derivationPath: string, network?: string): Wallet;
26
- /**
27
- * Create a Wallet from a raw seed (advanced usage)
28
- * @param seed - 64-byte seed (LongHash/Uint8Array)
29
- * @param derivationPath - BIP32/BIP44 derivation path
30
- * @param network - Network type: 'MAINNET' or 'TESTNET'
31
- * @returns New Wallet instance
32
- * @example
33
- * const wallet = Wallet.fromSeed(
34
- * new Uint8Array(64),
35
- * "m/44'/145'/0'/0",
36
- * 'MAINNET'
37
- * );
38
- */
39
- static fromSeed(seed: LongHash, derivationPath: string, network?: string): Wallet;
40
- /**
41
- * Private constructor - use Wallet.fromMnemonic() or Wallet.fromSeed() factory methods instead
42
- */
43
- private constructor();
44
- private constructor();
20
+ private account;
21
+ constructor(seed: LongHash, derivationPath: string, network: string);
22
+ constructor(mnemonic: string[], derivationPath: string, network: string);
23
+ private static prefixesOf;
24
+ private static addressVersionOf;
25
+ private accountKey;
26
+ dispose(): void;
45
27
  getSecret(index: number): EcSecret;
46
- getTripleOf(address: PaymentAddress, maxLoops?: number): {
47
- secret: EcSecret;
48
- publicKey: EcPublic;
49
- address: PaymentAddress;
50
- } | undefined;
28
+ private publicKeyOf;
51
29
  getPublicKey(index: number): EcPublic;
52
- getPublicKeys(count?: number, from?: number): EcPublic[];
30
+ getPublicKeys(count?: number, from?: number): Array<EcPublic>;
31
+ private addressOf;
53
32
  getAddress(index: number): PaymentAddress;
54
- getAddresses(count?: number, from?: number): PaymentAddress[];
55
- getTriple(index: number): {
56
- secret: EcSecret;
57
- publicKey: EcPublic;
58
- address: PaymentAddress;
59
- };
33
+ getAddresses(count?: number, from?: number): Array<PaymentAddress>;
34
+ getTriple(index: number): WalletTriple;
35
+ getTripleOf(address: PaymentAddress, maxLoops?: number): WalletTriple | undefined;
60
36
  deriveAccount(derivationPath: string): Wallet;
61
37
  }
62
38
  export default Wallet;
@@ -1,6 +1,10 @@
1
- import { WalletDataNative } from './wasm/glue';
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
2
5
  import { EncryptedSeed } from './Hash';
3
6
  import { HdPublic } from './HdPublic';
7
+ import { WalletDataNative } from './wasm/glue';
4
8
  export declare class WalletData {
5
9
  mnemonics?: Array<string>;
6
10
  encryptedSeed?: EncryptedSeed;
@@ -1,8 +1,11 @@
1
- import { LongHash } from './Hash';
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ import { EncryptedSeed, LongHash } from './Hash';
2
6
  import { WalletData } from './WalletData';
3
- import { EncryptedSeed } from './Hash';
4
7
  export declare class WalletManager {
5
- static createWallet(password: string, normalizedPassphrase?: string): WalletData | undefined;
8
+ static createSimple(password: string, normalizedPassphrase?: string): WalletData | undefined;
6
9
  static decryptSeed(password: string, encryptedSeed: EncryptedSeed): LongHash | undefined;
7
10
  }
8
11
  export default WalletManager;
@@ -0,0 +1,53 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ /**
6
+ * WalletUtils - Centralized wallet operations to reduce code duplication
7
+ * across different frontend implementations
8
+ */
9
+ export declare class WalletUtils {
10
+ /**
11
+ * Fix encrypted seed format - ensures proper 96-byte length
12
+ * This function was duplicated in multiple places in vm-lab
13
+ */
14
+ static fixSeed(seed: Uint8Array): Uint8Array;
15
+ /**
16
+ * Create wallet from encrypted seed - consolidates the common pattern:
17
+ * fixSeed() -> decryptSeed() -> new Wallet()
18
+ */
19
+ static createWalletFromEncryptedSeed(kth: any, selectedWallet: any, password?: string): any;
20
+ /**
21
+ * Normalize Bitcoin Cash address - handles bitcoincash: prefix consistently
22
+ */
23
+ static normalizeAddress(address: string, withPrefix?: boolean): string;
24
+ /**
25
+ * Convert BCH to satoshis (uses existing Bitcoin utility)
26
+ */
27
+ static bitcoinToSatoshis(amount: number): bigint;
28
+ /**
29
+ * Convert satoshis to BCH (uses existing Bitcoin utility)
30
+ */
31
+ static satoshisToBitcoin(satoshis: bigint): number;
32
+ /**
33
+ * Convert token amount to token satoshis (for 2-decimal tokens like mUSD)
34
+ */
35
+ static tokenToSatoshis(amount: number, decimals?: number): number;
36
+ /**
37
+ * Convert token satoshis to token amount
38
+ */
39
+ static satoshisToToken(satoshis: number, decimals?: number): number;
40
+ /**
41
+ * Validate if a wallet is ready for transactions
42
+ */
43
+ static validateWalletForTransaction(selectedWallet: any): void;
44
+ /**
45
+ * Get first address from wallet
46
+ */
47
+ static getFirstAddress(selectedWallet: any): string;
48
+ /**
49
+ * Get change address from wallet (typically same as first address for now)
50
+ */
51
+ static getChangeAddress(selectedWallet: any, addressIndex?: number): string;
52
+ }
53
+ export default WalletUtils;
@@ -1,3 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  import { Hash } from './Hash';
2
6
  export declare function bytesToHexStr(bytes: Uint8Array): string;
3
7
  export declare function hexStrToBytes(hex: string): Uint8Array;
package/types/env.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
1
5
  export declare const IS_WORKER: boolean;
2
6
  export declare const IS_WEB_MAIN_THREAD: boolean;
3
7
  export declare const IS_NODE_MAIN_THREAD: boolean;
@@ -0,0 +1,6 @@
1
+ // Copyright (c) 2016-present Knuth Project developers.
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ export declare function debugLog(...args: unknown[]): void;
6
+ export declare function debugWarn(...args: unknown[]): void;