-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpsbtBase.ts
More file actions
83 lines (79 loc) · 2.57 KB
/
psbtBase.ts
File metadata and controls
83 lines (79 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import type { PsbtInputData, PsbtOutputData, WasmBIP32 } from "./wasm/wasm_utxo.js";
import { BIP32 } from "./bip32.js";
import type { PsbtKvKey } from "./fixedScriptWallet/BitGoKeySubtype.js";
interface WasmPsbtBase {
input_count(): number;
output_count(): number;
version(): number;
lock_time(): number;
unsigned_tx_id(): string;
serialize(): Uint8Array;
get_inputs(): unknown;
get_outputs(): unknown;
get_global_xpubs(): unknown;
remove_input(index: number): void;
remove_output(index: number): void;
set_kv(key: unknown, value: Uint8Array): void;
get_kv(key: unknown): Uint8Array | null | undefined;
set_input_kv(index: number, key: unknown, value: Uint8Array): void;
get_input_kv(index: number, key: unknown): Uint8Array | null | undefined;
set_output_kv(index: number, key: unknown, value: Uint8Array): void;
get_output_kv(index: number, key: unknown): Uint8Array | null | undefined;
}
export abstract class PsbtBase<W extends WasmPsbtBase> {
protected _wasm: W;
constructor(wasm: W) {
this._wasm = wasm;
}
inputCount(): number {
return this._wasm.input_count();
}
outputCount(): number {
return this._wasm.output_count();
}
version(): number {
return this._wasm.version();
}
lockTime(): number {
return this._wasm.lock_time();
}
unsignedTxId(): string {
return this._wasm.unsigned_tx_id();
}
serialize(): Uint8Array {
return this._wasm.serialize();
}
getInputs(): PsbtInputData[] {
return this._wasm.get_inputs() as PsbtInputData[];
}
getOutputs(): PsbtOutputData[] {
return this._wasm.get_outputs() as PsbtOutputData[];
}
getGlobalXpubs(): BIP32[] {
return (this._wasm.get_global_xpubs() as WasmBIP32[]).map((w) => BIP32.fromWasm(w));
}
removeInput(index: number): void {
this._wasm.remove_input(index);
}
removeOutput(index: number): void {
this._wasm.remove_output(index);
}
setKV(key: PsbtKvKey, value: Uint8Array): void {
this._wasm.set_kv(key, value);
}
getKV(key: PsbtKvKey): Uint8Array | undefined {
return this._wasm.get_kv(key) ?? undefined;
}
setInputKV(index: number, key: PsbtKvKey, value: Uint8Array): void {
this._wasm.set_input_kv(index, key, value);
}
getInputKV(index: number, key: PsbtKvKey): Uint8Array | undefined {
return this._wasm.get_input_kv(index, key) ?? undefined;
}
setOutputKV(index: number, key: PsbtKvKey, value: Uint8Array): void {
this._wasm.set_output_kv(index, key, value);
}
getOutputKV(index: number, key: PsbtKvKey): Uint8Array | undefined {
return this._wasm.get_output_kv(index, key) ?? undefined;
}
}