@ledgerhq/hw-app-btc 10.0.4 → 10.0.5-next.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/CHANGELOG.md +7 -0
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +6 -8
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts +1 -1
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +5 -6
- package/lib/BtcNew.js.map +1 -1
- package/lib/BtcOld.d.ts +1 -1
- package/lib/BtcOld.d.ts.map +1 -1
- package/lib/BtcOld.js +2 -5
- package/lib/BtcOld.js.map +1 -1
- package/lib/buffertools.js +3 -3
- package/lib/buffertools.js.map +1 -1
- package/lib/createTransaction.d.ts +1 -6
- package/lib/createTransaction.d.ts.map +1 -1
- package/lib/createTransaction.js +5 -13
- package/lib/createTransaction.js.map +1 -1
- package/lib/finalizeInput.d.ts.map +1 -1
- package/lib/finalizeInput.js.map +1 -1
- package/lib/getAppAndVersion.d.ts.map +1 -1
- package/lib/getAppAndVersion.js.map +1 -1
- package/lib/getTrustedInput.d.ts.map +1 -1
- package/lib/getTrustedInput.js +5 -12
- package/lib/getTrustedInput.js.map +1 -1
- package/lib/getTrustedInputBIP143.d.ts.map +1 -1
- package/lib/getTrustedInputBIP143.js.map +1 -1
- package/lib/getWalletPublicKey.d.ts.map +1 -1
- package/lib/getWalletPublicKey.js.map +1 -1
- package/lib/newops/accounttype.d.ts.map +1 -1
- package/lib/newops/accounttype.js +2 -6
- package/lib/newops/accounttype.js.map +1 -1
- package/lib/newops/appClient.d.ts.map +1 -1
- package/lib/newops/appClient.js +7 -14
- package/lib/newops/appClient.js.map +1 -1
- package/lib/newops/clientCommands.d.ts.map +1 -1
- package/lib/newops/clientCommands.js +2 -2
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib/newops/merkelizedPsbt.js +4 -4
- package/lib/newops/merkelizedPsbt.js.map +1 -1
- package/lib/newops/merkle.d.ts.map +1 -1
- package/lib/newops/merkle.js.map +1 -1
- package/lib/newops/merkleMap.js +2 -2
- package/lib/newops/merkleMap.js.map +1 -1
- package/lib/newops/policy.d.ts.map +1 -1
- package/lib/newops/policy.js +2 -2
- package/lib/newops/policy.js.map +1 -1
- package/lib/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib/newops/psbtFinalizer.js.map +1 -1
- package/lib/newops/psbtv2.d.ts.map +1 -1
- package/lib/newops/psbtv2.js +6 -6
- package/lib/newops/psbtv2.js.map +1 -1
- package/lib/serializeTransaction.d.ts.map +1 -1
- package/lib/serializeTransaction.js +3 -4
- package/lib/serializeTransaction.js.map +1 -1
- package/lib/signMessage.d.ts.map +1 -1
- package/lib/signMessage.js +2 -6
- package/lib/signMessage.js.map +1 -1
- package/lib/signP2SHTransaction.d.ts +1 -6
- package/lib/signP2SHTransaction.d.ts.map +1 -1
- package/lib/signP2SHTransaction.js +2 -6
- package/lib/signP2SHTransaction.js.map +1 -1
- package/lib/signTransaction.d.ts.map +1 -1
- package/lib/signTransaction.js +2 -7
- package/lib/signTransaction.js.map +1 -1
- package/lib/splitTransaction.d.ts.map +1 -1
- package/lib/splitTransaction.js.map +1 -1
- package/lib/startUntrustedHashTransactionInput.d.ts.map +1 -1
- package/lib/startUntrustedHashTransactionInput.js +1 -4
- package/lib/startUntrustedHashTransactionInput.js.map +1 -1
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +6 -8
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts +1 -1
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +6 -7
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/BtcOld.d.ts +1 -1
- package/lib-es/BtcOld.d.ts.map +1 -1
- package/lib-es/BtcOld.js +2 -5
- package/lib-es/BtcOld.js.map +1 -1
- package/lib-es/buffertools.js +3 -3
- package/lib-es/buffertools.js.map +1 -1
- package/lib-es/createTransaction.d.ts +1 -6
- package/lib-es/createTransaction.d.ts.map +1 -1
- package/lib-es/createTransaction.js +5 -13
- package/lib-es/createTransaction.js.map +1 -1
- package/lib-es/finalizeInput.d.ts.map +1 -1
- package/lib-es/finalizeInput.js.map +1 -1
- package/lib-es/getAppAndVersion.d.ts.map +1 -1
- package/lib-es/getAppAndVersion.js.map +1 -1
- package/lib-es/getTrustedInput.d.ts.map +1 -1
- package/lib-es/getTrustedInput.js +5 -12
- package/lib-es/getTrustedInput.js.map +1 -1
- package/lib-es/getTrustedInputBIP143.d.ts.map +1 -1
- package/lib-es/getTrustedInputBIP143.js.map +1 -1
- package/lib-es/getWalletPublicKey.d.ts.map +1 -1
- package/lib-es/getWalletPublicKey.js.map +1 -1
- package/lib-es/newops/accounttype.d.ts.map +1 -1
- package/lib-es/newops/accounttype.js +3 -7
- package/lib-es/newops/accounttype.js.map +1 -1
- package/lib-es/newops/appClient.d.ts.map +1 -1
- package/lib-es/newops/appClient.js +7 -14
- package/lib-es/newops/appClient.js.map +1 -1
- package/lib-es/newops/clientCommands.d.ts.map +1 -1
- package/lib-es/newops/clientCommands.js +2 -2
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib-es/newops/merkelizedPsbt.js +4 -4
- package/lib-es/newops/merkelizedPsbt.js.map +1 -1
- package/lib-es/newops/merkle.d.ts.map +1 -1
- package/lib-es/newops/merkle.js.map +1 -1
- package/lib-es/newops/merkleMap.js +2 -2
- package/lib-es/newops/merkleMap.js.map +1 -1
- package/lib-es/newops/policy.d.ts.map +1 -1
- package/lib-es/newops/policy.js +2 -2
- package/lib-es/newops/policy.js.map +1 -1
- package/lib-es/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib-es/newops/psbtFinalizer.js.map +1 -1
- package/lib-es/newops/psbtv2.d.ts.map +1 -1
- package/lib-es/newops/psbtv2.js +7 -7
- package/lib-es/newops/psbtv2.js.map +1 -1
- package/lib-es/serializeTransaction.d.ts.map +1 -1
- package/lib-es/serializeTransaction.js +3 -4
- package/lib-es/serializeTransaction.js.map +1 -1
- package/lib-es/signMessage.d.ts.map +1 -1
- package/lib-es/signMessage.js +2 -6
- package/lib-es/signMessage.js.map +1 -1
- package/lib-es/signP2SHTransaction.d.ts +1 -6
- package/lib-es/signP2SHTransaction.d.ts.map +1 -1
- package/lib-es/signP2SHTransaction.js +3 -7
- package/lib-es/signP2SHTransaction.js.map +1 -1
- package/lib-es/signTransaction.d.ts.map +1 -1
- package/lib-es/signTransaction.js +2 -7
- package/lib-es/signTransaction.js.map +1 -1
- package/lib-es/splitTransaction.d.ts.map +1 -1
- package/lib-es/splitTransaction.js.map +1 -1
- package/lib-es/startUntrustedHashTransactionInput.d.ts.map +1 -1
- package/lib-es/startUntrustedHashTransactionInput.js +1 -4
- package/lib-es/startUntrustedHashTransactionInput.js.map +1 -1
- package/package.json +5 -5
- package/src/Btc.ts +17 -31
- package/src/BtcNew.ts +27 -62
- package/src/BtcOld.ts +8 -19
- package/src/buffertools.ts +3 -3
- package/src/createTransaction.ts +20 -52
- package/src/finalizeInput.ts +2 -5
- package/src/getAppAndVersion.ts +2 -6
- package/src/getTrustedInput.ts +12 -32
- package/src/getTrustedInputBIP143.ts +2 -4
- package/src/getWalletPublicKey.ts +3 -11
- package/src/newops/accounttype.ts +21 -76
- package/src/newops/appClient.ts +17 -39
- package/src/newops/clientCommands.ts +7 -16
- package/src/newops/merkelizedPsbt.ts +6 -14
- package/src/newops/merkle.ts +3 -10
- package/src/newops/merkleMap.ts +2 -2
- package/src/newops/policy.ts +5 -15
- package/src/newops/psbtFinalizer.ts +3 -8
- package/src/newops/psbtv2.ts +32 -85
- package/src/serializeTransaction.ts +5 -9
- package/src/signMessage.ts +5 -16
- package/src/signP2SHTransaction.ts +11 -34
- package/src/signTransaction.ts +3 -8
- package/src/splitTransaction.ts +3 -7
- package/src/startUntrustedHashTransactionInput.ts +7 -10
package/src/getAppAndVersion.ts
CHANGED
|
@@ -7,9 +7,7 @@ export type AppAndVersion = {
|
|
|
7
7
|
flags: number | Buffer;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export const getAppAndVersion = async (
|
|
11
|
-
transport: Transport
|
|
12
|
-
): Promise<AppAndVersion> => {
|
|
10
|
+
export const getAppAndVersion = async (transport: Transport): Promise<AppAndVersion> => {
|
|
13
11
|
const r = await transport.send(0xb0, 0x01, 0x00, 0x00);
|
|
14
12
|
let i = 0;
|
|
15
13
|
const format = r[i++];
|
|
@@ -27,9 +25,7 @@ export const getAppAndVersion = async (
|
|
|
27
25
|
};
|
|
28
26
|
};
|
|
29
27
|
|
|
30
|
-
export const checkIsBtcLegacy = async (
|
|
31
|
-
transport: Transport
|
|
32
|
-
): Promise<boolean> => {
|
|
28
|
+
export const checkIsBtcLegacy = async (transport: Transport): Promise<boolean> => {
|
|
33
29
|
try {
|
|
34
30
|
// Call old btc API, it will throw an exception with new btc app. It is a workaround to differentiate new/old btc nano app
|
|
35
31
|
await transport.send(0xe0, 0xc4, 0, 0);
|
package/src/getTrustedInput.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { createVarint } from "./varint";
|
|
|
6
6
|
export async function getTrustedInputRaw(
|
|
7
7
|
transport: Transport,
|
|
8
8
|
transactionData: Buffer,
|
|
9
|
-
indexLookup?: number | null | undefined
|
|
9
|
+
indexLookup?: number | null | undefined,
|
|
10
10
|
): Promise<string> {
|
|
11
11
|
let data;
|
|
12
12
|
let firstRound = false;
|
|
@@ -20,13 +20,7 @@ export async function getTrustedInputRaw(
|
|
|
20
20
|
data = transactionData;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const trustedInput = await transport.send(
|
|
24
|
-
0xe0,
|
|
25
|
-
0x42,
|
|
26
|
-
firstRound ? 0x00 : 0x80,
|
|
27
|
-
0x00,
|
|
28
|
-
data
|
|
29
|
-
);
|
|
23
|
+
const trustedInput = await transport.send(0xe0, 0x42, firstRound ? 0x00 : 0x80, 0x00, data);
|
|
30
24
|
const res = trustedInput.slice(0, trustedInput.length - 2).toString("hex");
|
|
31
25
|
return res;
|
|
32
26
|
}
|
|
@@ -34,10 +28,9 @@ export async function getTrustedInput(
|
|
|
34
28
|
transport: Transport,
|
|
35
29
|
indexLookup: number,
|
|
36
30
|
transaction: Transaction,
|
|
37
|
-
additionals: Array<string> = []
|
|
31
|
+
additionals: Array<string> = [],
|
|
38
32
|
): Promise<string> {
|
|
39
|
-
const { version, inputs, outputs, locktime, nExpiryHeight, extraData } =
|
|
40
|
-
transaction;
|
|
33
|
+
const { version, inputs, outputs, locktime, nExpiryHeight, extraData } = transaction;
|
|
41
34
|
|
|
42
35
|
if (!outputs || !locktime) {
|
|
43
36
|
throw new Error("getTrustedInput: locktime & outputs is expected");
|
|
@@ -53,16 +46,12 @@ export async function getTrustedInput(
|
|
|
53
46
|
|
|
54
47
|
while (offset !== script.length) {
|
|
55
48
|
const blockSize =
|
|
56
|
-
script.length - offset > MAX_SCRIPT_BLOCK
|
|
57
|
-
? MAX_SCRIPT_BLOCK
|
|
58
|
-
: script.length - offset;
|
|
49
|
+
script.length - offset > MAX_SCRIPT_BLOCK ? MAX_SCRIPT_BLOCK : script.length - offset;
|
|
59
50
|
|
|
60
51
|
if (offset + blockSize !== script.length) {
|
|
61
52
|
scriptBlocks.push(script.slice(offset, offset + blockSize));
|
|
62
53
|
} else {
|
|
63
|
-
scriptBlocks.push(
|
|
64
|
-
Buffer.concat([script.slice(offset, offset + blockSize), seq])
|
|
65
|
-
);
|
|
54
|
+
scriptBlocks.push(Buffer.concat([script.slice(offset, offset + blockSize), seq]));
|
|
66
55
|
}
|
|
67
56
|
|
|
68
57
|
offset += blockSize;
|
|
@@ -83,8 +72,7 @@ export async function getTrustedInput(
|
|
|
83
72
|
return res;
|
|
84
73
|
};
|
|
85
74
|
|
|
86
|
-
const processWholeScriptBlock = (block)
|
|
87
|
-
getTrustedInputRaw(transport, block);
|
|
75
|
+
const processWholeScriptBlock = block => getTrustedInputRaw(transport, block);
|
|
88
76
|
|
|
89
77
|
await getTrustedInputRaw(
|
|
90
78
|
transport,
|
|
@@ -94,16 +82,12 @@ export async function getTrustedInput(
|
|
|
94
82
|
transaction.nVersionGroupId || Buffer.alloc(0),
|
|
95
83
|
createVarint(inputs.length),
|
|
96
84
|
]),
|
|
97
|
-
indexLookup
|
|
85
|
+
indexLookup,
|
|
98
86
|
);
|
|
99
87
|
|
|
100
88
|
for (const input of inputs) {
|
|
101
|
-
const isXSTV2 =
|
|
102
|
-
|
|
103
|
-
Buffer.compare(version, Buffer.from([0x02, 0x00, 0x00, 0x00])) === 0;
|
|
104
|
-
const treeField = isDecred
|
|
105
|
-
? input.tree || Buffer.from([0x00])
|
|
106
|
-
: Buffer.alloc(0);
|
|
89
|
+
const isXSTV2 = isXST && Buffer.compare(version, Buffer.from([0x02, 0x00, 0x00, 0x00])) === 0;
|
|
90
|
+
const treeField = isDecred ? input.tree || Buffer.from([0x00]) : Buffer.alloc(0);
|
|
107
91
|
const data = Buffer.concat([
|
|
108
92
|
input.prevout,
|
|
109
93
|
treeField,
|
|
@@ -147,14 +131,10 @@ export async function getTrustedInput(
|
|
|
147
131
|
|
|
148
132
|
if (endData.length) {
|
|
149
133
|
const data = Buffer.concat(endData);
|
|
150
|
-
extraPart = isDecred
|
|
151
|
-
? data
|
|
152
|
-
: Buffer.concat([createVarint(data.length), data]);
|
|
134
|
+
extraPart = isDecred ? data : Buffer.concat([createVarint(data.length), data]);
|
|
153
135
|
}
|
|
154
136
|
|
|
155
|
-
const res = await processScriptBlocks(
|
|
156
|
-
Buffer.concat([locktime, extraPart || Buffer.alloc(0)])
|
|
157
|
-
);
|
|
137
|
+
const res = await processScriptBlocks(Buffer.concat([locktime, extraPart || Buffer.alloc(0)]));
|
|
158
138
|
invariant(res, "missing result in processScriptBlocks");
|
|
159
139
|
return res;
|
|
160
140
|
}
|
|
@@ -6,7 +6,7 @@ export function getTrustedInputBIP143(
|
|
|
6
6
|
transport: Transport,
|
|
7
7
|
indexLookup: number,
|
|
8
8
|
transaction: Transaction,
|
|
9
|
-
additionals: Array<string> = []
|
|
9
|
+
additionals: Array<string> = [],
|
|
10
10
|
): string {
|
|
11
11
|
if (!transaction) {
|
|
12
12
|
throw new Error("getTrustedInputBIP143: missing tx");
|
|
@@ -19,9 +19,7 @@ export function getTrustedInputBIP143(
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
let hash = shajs("sha256")
|
|
22
|
-
.update(
|
|
23
|
-
shajs("sha256").update(serializeTransaction(transaction, true)).digest()
|
|
24
|
-
)
|
|
22
|
+
.update(shajs("sha256").update(serializeTransaction(transaction, true)).digest())
|
|
25
23
|
.digest();
|
|
26
24
|
const data = Buffer.alloc(4);
|
|
27
25
|
data.writeUInt32LE(indexLookup, 0);
|
|
@@ -4,12 +4,7 @@ import { bip32asBuffer } from "./bip32";
|
|
|
4
4
|
/**
|
|
5
5
|
* address format is one of legacy | p2sh | bech32 | cashaddr
|
|
6
6
|
*/
|
|
7
|
-
export type AddressFormat =
|
|
8
|
-
| "legacy"
|
|
9
|
-
| "p2sh"
|
|
10
|
-
| "bech32"
|
|
11
|
-
| "bech32m"
|
|
12
|
-
| "cashaddr";
|
|
7
|
+
export type AddressFormat = "legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr";
|
|
13
8
|
const addressFormatMap = {
|
|
14
9
|
legacy: 0,
|
|
15
10
|
p2sh: 1,
|
|
@@ -22,7 +17,7 @@ export async function getWalletPublicKey(
|
|
|
22
17
|
path: string;
|
|
23
18
|
verify?: boolean;
|
|
24
19
|
format?: AddressFormat;
|
|
25
|
-
}
|
|
20
|
+
},
|
|
26
21
|
): Promise<{
|
|
27
22
|
publicKey: string;
|
|
28
23
|
bitcoinAddress: string;
|
|
@@ -49,10 +44,7 @@ export async function getWalletPublicKey(
|
|
|
49
44
|
.slice(1 + publicKeyLength + 1, 1 + publicKeyLength + 1 + addressLength)
|
|
50
45
|
.toString("ascii");
|
|
51
46
|
const chainCode = response
|
|
52
|
-
.slice(
|
|
53
|
-
1 + publicKeyLength + 1 + addressLength,
|
|
54
|
-
1 + publicKeyLength + 1 + addressLength + 32
|
|
55
|
-
)
|
|
47
|
+
.slice(1 + publicKeyLength + 1 + addressLength, 1 + publicKeyLength + 1 + addressLength + 32)
|
|
56
48
|
.toString("hex");
|
|
57
49
|
return {
|
|
58
50
|
publicKey,
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { crypto } from "bitcoinjs-lib";
|
|
2
2
|
import { pointAddScalar } from "tiny-secp256k1";
|
|
3
3
|
import { BufferWriter } from "../buffertools";
|
|
4
|
-
import {
|
|
5
|
-
HASH_SIZE,
|
|
6
|
-
OP_CHECKSIG,
|
|
7
|
-
OP_DUP,
|
|
8
|
-
OP_EQUAL,
|
|
9
|
-
OP_EQUALVERIFY,
|
|
10
|
-
OP_HASH160,
|
|
11
|
-
} from "../constants";
|
|
4
|
+
import { HASH_SIZE, OP_CHECKSIG, OP_DUP, OP_EQUAL, OP_EQUALVERIFY, OP_HASH160 } from "../constants";
|
|
12
5
|
import { hashPublicKey } from "../hashPublicKey";
|
|
13
6
|
import { DefaultDescriptorTemplate } from "./policy";
|
|
14
7
|
import { PsbtV2 } from "./psbtv2";
|
|
@@ -51,7 +44,7 @@ export interface AccountType {
|
|
|
51
44
|
inputTx: Buffer | undefined,
|
|
52
45
|
spentOutput: SpentOutput,
|
|
53
46
|
pubkeys: Buffer[],
|
|
54
|
-
pathElems: number[][]
|
|
47
|
+
pathElems: number[][],
|
|
55
48
|
): void;
|
|
56
49
|
|
|
57
50
|
/**
|
|
@@ -63,12 +56,7 @@ export interface AccountType {
|
|
|
63
56
|
* @param pubkeys The 33 byte ecdsa compressed public keys involved in this output
|
|
64
57
|
* @param paths The paths corresponding to the pubkeys, in same order.
|
|
65
58
|
*/
|
|
66
|
-
setOwnOutput(
|
|
67
|
-
i: number,
|
|
68
|
-
cond: SpendingCondition,
|
|
69
|
-
pubkeys: Buffer[],
|
|
70
|
-
paths: number[][]
|
|
71
|
-
): void;
|
|
59
|
+
setOwnOutput(i: number, cond: SpendingCondition, pubkeys: Buffer[], paths: number[][]): void;
|
|
72
60
|
|
|
73
61
|
/**
|
|
74
62
|
* Returns the descriptor template for this account type. Currently only
|
|
@@ -105,7 +93,7 @@ abstract class SingleKeyAccount extends BaseAccount {
|
|
|
105
93
|
inputTx: Buffer | undefined,
|
|
106
94
|
spentOutput: SpentOutput,
|
|
107
95
|
pubkeys: Buffer[],
|
|
108
|
-
pathElems: number[][]
|
|
96
|
+
pathElems: number[][],
|
|
109
97
|
) {
|
|
110
98
|
if (pubkeys.length != 1) {
|
|
111
99
|
throw new Error("Expected single key, got " + pubkeys.length);
|
|
@@ -120,15 +108,10 @@ abstract class SingleKeyAccount extends BaseAccount {
|
|
|
120
108
|
inputTx: Buffer | undefined,
|
|
121
109
|
spentOutput: SpentOutput,
|
|
122
110
|
pubkey: Buffer,
|
|
123
|
-
path: number[]
|
|
111
|
+
path: number[],
|
|
124
112
|
);
|
|
125
113
|
|
|
126
|
-
setOwnOutput(
|
|
127
|
-
i: number,
|
|
128
|
-
cond: SpendingCondition,
|
|
129
|
-
pubkeys: Buffer[],
|
|
130
|
-
paths: number[][]
|
|
131
|
-
) {
|
|
114
|
+
setOwnOutput(i: number, cond: SpendingCondition, pubkeys: Buffer[], paths: number[][]) {
|
|
132
115
|
if (pubkeys.length != 1) {
|
|
133
116
|
throw new Error("Expected single key, got " + pubkeys.length);
|
|
134
117
|
}
|
|
@@ -141,7 +124,7 @@ abstract class SingleKeyAccount extends BaseAccount {
|
|
|
141
124
|
i: number,
|
|
142
125
|
cond: SpendingCondition,
|
|
143
126
|
pubkey: Buffer,
|
|
144
|
-
path: number[]
|
|
127
|
+
path: number[],
|
|
145
128
|
);
|
|
146
129
|
}
|
|
147
130
|
|
|
@@ -160,7 +143,7 @@ export class p2pkh extends SingleKeyAccount {
|
|
|
160
143
|
inputTx: Buffer | undefined,
|
|
161
144
|
_spentOutput: SpentOutput,
|
|
162
145
|
pubkey: Buffer,
|
|
163
|
-
path: number[]
|
|
146
|
+
path: number[],
|
|
164
147
|
) {
|
|
165
148
|
if (!inputTx) {
|
|
166
149
|
throw new Error("Full input base transaction required");
|
|
@@ -169,12 +152,7 @@ export class p2pkh extends SingleKeyAccount {
|
|
|
169
152
|
this.psbt.setInputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
170
153
|
}
|
|
171
154
|
|
|
172
|
-
setSingleKeyOutput(
|
|
173
|
-
i: number,
|
|
174
|
-
cond: SpendingCondition,
|
|
175
|
-
pubkey: Buffer,
|
|
176
|
-
path: number[]
|
|
177
|
-
) {
|
|
155
|
+
setSingleKeyOutput(i: number, cond: SpendingCondition, pubkey: Buffer, path: number[]) {
|
|
178
156
|
this.psbt.setOutputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
179
157
|
}
|
|
180
158
|
|
|
@@ -198,23 +176,14 @@ export class p2tr extends SingleKeyAccount {
|
|
|
198
176
|
_inputTx: Buffer | undefined,
|
|
199
177
|
spentOutput: SpentOutput,
|
|
200
178
|
pubkey: Buffer,
|
|
201
|
-
path: number[]
|
|
179
|
+
path: number[],
|
|
202
180
|
) {
|
|
203
181
|
const xonly = pubkey.slice(1);
|
|
204
182
|
this.psbt.setInputTapBip32Derivation(i, xonly, [], this.masterFp, path);
|
|
205
|
-
this.psbt.setInputWitnessUtxo(
|
|
206
|
-
i,
|
|
207
|
-
spentOutput.amount,
|
|
208
|
-
spentOutput.cond.scriptPubKey
|
|
209
|
-
);
|
|
183
|
+
this.psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.cond.scriptPubKey);
|
|
210
184
|
}
|
|
211
185
|
|
|
212
|
-
setSingleKeyOutput(
|
|
213
|
-
i: number,
|
|
214
|
-
cond: SpendingCondition,
|
|
215
|
-
pubkey: Buffer,
|
|
216
|
-
path: number[]
|
|
217
|
-
) {
|
|
186
|
+
setSingleKeyOutput(i: number, cond: SpendingCondition, pubkey: Buffer, path: number[]) {
|
|
218
187
|
const xonly = pubkey.slice(1);
|
|
219
188
|
this.psbt.setOutputTapBip32Derivation(i, xonly, [], this.masterFp, path);
|
|
220
189
|
}
|
|
@@ -251,10 +220,7 @@ export class p2tr extends SingleKeyAccount {
|
|
|
251
220
|
// the first byte, which represent the oddness/evenness. In schnorr all
|
|
252
221
|
// pubkeys are even.
|
|
253
222
|
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#public-key-conversion
|
|
254
|
-
const evenEcdsaPubkey = Buffer.concat([
|
|
255
|
-
Buffer.from([0x02]),
|
|
256
|
-
internalPubkey,
|
|
257
|
-
]);
|
|
223
|
+
const evenEcdsaPubkey = Buffer.concat([Buffer.from([0x02]), internalPubkey]);
|
|
258
224
|
const tweak = this.hashTapTweak(internalPubkey);
|
|
259
225
|
|
|
260
226
|
// Q = P + int(hash_TapTweak(bytes(P)))G
|
|
@@ -282,7 +248,7 @@ export class p2wpkhWrapped extends SingleKeyAccount {
|
|
|
282
248
|
inputTx: Buffer | undefined,
|
|
283
249
|
spentOutput: SpentOutput,
|
|
284
250
|
pubkey: Buffer,
|
|
285
|
-
path: number[]
|
|
251
|
+
path: number[],
|
|
286
252
|
) {
|
|
287
253
|
if (!inputTx) {
|
|
288
254
|
throw new Error("Full input base transaction required");
|
|
@@ -292,30 +258,18 @@ export class p2wpkhWrapped extends SingleKeyAccount {
|
|
|
292
258
|
|
|
293
259
|
const userSuppliedRedeemScript = spentOutput.cond.redeemScript;
|
|
294
260
|
const expectedRedeemScript = this.createRedeemScript(pubkey);
|
|
295
|
-
if (
|
|
296
|
-
userSuppliedRedeemScript &&
|
|
297
|
-
!expectedRedeemScript.equals(userSuppliedRedeemScript)
|
|
298
|
-
) {
|
|
261
|
+
if (userSuppliedRedeemScript && !expectedRedeemScript.equals(userSuppliedRedeemScript)) {
|
|
299
262
|
// At what point might a user set the redeemScript on its own?
|
|
300
263
|
throw new Error(`User-supplied redeemScript ${userSuppliedRedeemScript.toString(
|
|
301
|
-
"hex"
|
|
264
|
+
"hex",
|
|
302
265
|
)} doesn't
|
|
303
266
|
match expected ${expectedRedeemScript.toString("hex")} for input ${i}`);
|
|
304
267
|
}
|
|
305
268
|
this.psbt.setInputRedeemScript(i, expectedRedeemScript);
|
|
306
|
-
this.psbt.setInputWitnessUtxo(
|
|
307
|
-
i,
|
|
308
|
-
spentOutput.amount,
|
|
309
|
-
spentOutput.cond.scriptPubKey
|
|
310
|
-
);
|
|
269
|
+
this.psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.cond.scriptPubKey);
|
|
311
270
|
}
|
|
312
271
|
|
|
313
|
-
setSingleKeyOutput(
|
|
314
|
-
i: number,
|
|
315
|
-
cond: SpendingCondition,
|
|
316
|
-
pubkey: Buffer,
|
|
317
|
-
path: number[]
|
|
318
|
-
) {
|
|
272
|
+
setSingleKeyOutput(i: number, cond: SpendingCondition, pubkey: Buffer, path: number[]) {
|
|
319
273
|
this.psbt.setOutputRedeemScript(i, cond.redeemScript!);
|
|
320
274
|
this.psbt.setOutputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
321
275
|
}
|
|
@@ -344,26 +298,17 @@ export class p2wpkh extends SingleKeyAccount {
|
|
|
344
298
|
inputTx: Buffer | undefined,
|
|
345
299
|
spentOutput: SpentOutput,
|
|
346
300
|
pubkey: Buffer,
|
|
347
|
-
path: number[]
|
|
301
|
+
path: number[],
|
|
348
302
|
) {
|
|
349
303
|
if (!inputTx) {
|
|
350
304
|
throw new Error("Full input base transaction required");
|
|
351
305
|
}
|
|
352
306
|
this.psbt.setInputNonWitnessUtxo(i, inputTx);
|
|
353
307
|
this.psbt.setInputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
354
|
-
this.psbt.setInputWitnessUtxo(
|
|
355
|
-
i,
|
|
356
|
-
spentOutput.amount,
|
|
357
|
-
spentOutput.cond.scriptPubKey
|
|
358
|
-
);
|
|
308
|
+
this.psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.cond.scriptPubKey);
|
|
359
309
|
}
|
|
360
310
|
|
|
361
|
-
setSingleKeyOutput(
|
|
362
|
-
i: number,
|
|
363
|
-
cond: SpendingCondition,
|
|
364
|
-
pubkey: Buffer,
|
|
365
|
-
path: number[]
|
|
366
|
-
) {
|
|
311
|
+
setSingleKeyOutput(i: number, cond: SpendingCondition, pubkey: Buffer, path: number[]) {
|
|
367
312
|
this.psbt.setOutputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
368
313
|
}
|
|
369
314
|
|
package/src/newops/appClient.ts
CHANGED
|
@@ -38,16 +38,9 @@ export class AppClient {
|
|
|
38
38
|
private async makeRequest(
|
|
39
39
|
ins: BitcoinIns,
|
|
40
40
|
data: Buffer,
|
|
41
|
-
cci?: ClientCommandInterpreter
|
|
41
|
+
cci?: ClientCommandInterpreter,
|
|
42
42
|
): Promise<Buffer> {
|
|
43
|
-
let response: Buffer = await this.transport.send(
|
|
44
|
-
CLA_BTC,
|
|
45
|
-
ins,
|
|
46
|
-
0,
|
|
47
|
-
0,
|
|
48
|
-
data,
|
|
49
|
-
[0x9000, 0xe000]
|
|
50
|
-
);
|
|
43
|
+
let response: Buffer = await this.transport.send(CLA_BTC, ins, 0, 0, data, [0x9000, 0xe000]);
|
|
51
44
|
while (response.readUInt16BE(response.length - 2) === 0xe000) {
|
|
52
45
|
if (!cci) {
|
|
53
46
|
throw new Error("Unexpected SW_INTERRUPTED_EXECUTION");
|
|
@@ -62,25 +55,19 @@ export class AppClient {
|
|
|
62
55
|
0,
|
|
63
56
|
0,
|
|
64
57
|
commandResponse,
|
|
65
|
-
[0x9000, 0xe000]
|
|
58
|
+
[0x9000, 0xe000],
|
|
66
59
|
);
|
|
67
60
|
}
|
|
68
61
|
return response.slice(0, -2); // drop the status word (can only be 0x9000 at this point)
|
|
69
62
|
}
|
|
70
63
|
|
|
71
|
-
async getExtendedPubkey(
|
|
72
|
-
display: boolean,
|
|
73
|
-
pathElements: number[]
|
|
74
|
-
): Promise<string> {
|
|
64
|
+
async getExtendedPubkey(display: boolean, pathElements: number[]): Promise<string> {
|
|
75
65
|
if (pathElements.length > 6) {
|
|
76
66
|
throw new Error("Path too long. At most 6 levels allowed.");
|
|
77
67
|
}
|
|
78
68
|
const response = await this.makeRequest(
|
|
79
69
|
BitcoinIns.GET_PUBKEY,
|
|
80
|
-
Buffer.concat([
|
|
81
|
-
Buffer.from(display ? [1] : [0]),
|
|
82
|
-
pathElementsToBuffer(pathElements),
|
|
83
|
-
])
|
|
70
|
+
Buffer.concat([Buffer.from(display ? [1] : [0]), pathElementsToBuffer(pathElements)]),
|
|
84
71
|
);
|
|
85
72
|
return response.toString("ascii");
|
|
86
73
|
}
|
|
@@ -90,10 +77,9 @@ export class AppClient {
|
|
|
90
77
|
walletHMAC: Buffer | null,
|
|
91
78
|
change: number,
|
|
92
79
|
addressIndex: number,
|
|
93
|
-
display: boolean
|
|
80
|
+
display: boolean,
|
|
94
81
|
): Promise<string> {
|
|
95
|
-
if (change !== 0 && change !== 1)
|
|
96
|
-
throw new Error("Change can only be 0 or 1");
|
|
82
|
+
if (change !== 0 && change !== 1) throw new Error("Change can only be 0 or 1");
|
|
97
83
|
if (addressIndex < 0 || !Number.isInteger(addressIndex))
|
|
98
84
|
throw new Error("Invalid address index");
|
|
99
85
|
|
|
@@ -102,9 +88,7 @@ export class AppClient {
|
|
|
102
88
|
}
|
|
103
89
|
|
|
104
90
|
const clientInterpreter = new ClientCommandInterpreter(() => {});
|
|
105
|
-
clientInterpreter.addKnownList(
|
|
106
|
-
walletPolicy.keys.map((k) => Buffer.from(k, "ascii"))
|
|
107
|
-
);
|
|
91
|
+
clientInterpreter.addKnownList(walletPolicy.keys.map(k => Buffer.from(k, "ascii")));
|
|
108
92
|
clientInterpreter.addKnownPreimage(walletPolicy.serialize());
|
|
109
93
|
|
|
110
94
|
const addressIndexBuffer = Buffer.alloc(4);
|
|
@@ -119,7 +103,7 @@ export class AppClient {
|
|
|
119
103
|
Buffer.from([change]),
|
|
120
104
|
addressIndexBuffer,
|
|
121
105
|
]),
|
|
122
|
-
clientInterpreter
|
|
106
|
+
clientInterpreter,
|
|
123
107
|
);
|
|
124
108
|
|
|
125
109
|
return response.toString("ascii");
|
|
@@ -129,7 +113,7 @@ export class AppClient {
|
|
|
129
113
|
psbt: PsbtV2,
|
|
130
114
|
walletPolicy: WalletPolicy,
|
|
131
115
|
walletHMAC: Buffer | null,
|
|
132
|
-
progressCallback: () => void
|
|
116
|
+
progressCallback: () => void,
|
|
133
117
|
): Promise<Map<number, Buffer>> {
|
|
134
118
|
const merkelizedPsbt = new MerkelizedPsbt(psbt);
|
|
135
119
|
|
|
@@ -140,9 +124,7 @@ export class AppClient {
|
|
|
140
124
|
const clientInterpreter = new ClientCommandInterpreter(progressCallback);
|
|
141
125
|
|
|
142
126
|
// prepare ClientCommandInterpreter
|
|
143
|
-
clientInterpreter.addKnownList(
|
|
144
|
-
walletPolicy.keys.map((k) => Buffer.from(k, "ascii"))
|
|
145
|
-
);
|
|
127
|
+
clientInterpreter.addKnownList(walletPolicy.keys.map(k => Buffer.from(k, "ascii")));
|
|
146
128
|
clientInterpreter.addKnownPreimage(walletPolicy.serialize());
|
|
147
129
|
|
|
148
130
|
clientInterpreter.addKnownMapping(merkelizedPsbt.globalMerkleMap);
|
|
@@ -155,11 +137,11 @@ export class AppClient {
|
|
|
155
137
|
|
|
156
138
|
clientInterpreter.addKnownList(merkelizedPsbt.inputMapCommitments);
|
|
157
139
|
const inputMapsRoot = new Merkle(
|
|
158
|
-
merkelizedPsbt.inputMapCommitments.map(
|
|
140
|
+
merkelizedPsbt.inputMapCommitments.map(m => hashLeaf(m)),
|
|
159
141
|
).getRoot();
|
|
160
142
|
clientInterpreter.addKnownList(merkelizedPsbt.outputMapCommitments);
|
|
161
143
|
const outputMapsRoot = new Merkle(
|
|
162
|
-
merkelizedPsbt.outputMapCommitments.map(
|
|
144
|
+
merkelizedPsbt.outputMapCommitments.map(m => hashLeaf(m)),
|
|
163
145
|
).getRoot();
|
|
164
146
|
|
|
165
147
|
await this.makeRequest(
|
|
@@ -173,7 +155,7 @@ export class AppClient {
|
|
|
173
155
|
walletPolicy.getWalletId(),
|
|
174
156
|
walletHMAC || Buffer.alloc(32, 0),
|
|
175
157
|
]),
|
|
176
|
-
clientInterpreter
|
|
158
|
+
clientInterpreter,
|
|
177
159
|
);
|
|
178
160
|
|
|
179
161
|
const yielded = clientInterpreter.getYielded();
|
|
@@ -204,16 +186,12 @@ export class AppClient {
|
|
|
204
186
|
}
|
|
205
187
|
|
|
206
188
|
clientInterpreter.addKnownList(chunks);
|
|
207
|
-
const chunksRoot = new Merkle(chunks.map(
|
|
189
|
+
const chunksRoot = new Merkle(chunks.map(m => hashLeaf(m))).getRoot();
|
|
208
190
|
|
|
209
191
|
const response = await this.makeRequest(
|
|
210
192
|
BitcoinIns.SIGN_MESSAGE,
|
|
211
|
-
Buffer.concat([
|
|
212
|
-
|
|
213
|
-
createVarint(message.length),
|
|
214
|
-
chunksRoot,
|
|
215
|
-
]),
|
|
216
|
-
clientInterpreter
|
|
193
|
+
Buffer.concat([pathElementsToBuffer(pathElements), createVarint(message.length), chunksRoot]),
|
|
194
|
+
clientInterpreter,
|
|
217
195
|
);
|
|
218
196
|
|
|
219
197
|
return response.toString("base64");
|
|
@@ -121,9 +121,7 @@ export class GetMerkleLeafProofCommand extends ClientCommand {
|
|
|
121
121
|
tree_size = reqBuf.readVarInt();
|
|
122
122
|
leaf_index = reqBuf.readVarInt();
|
|
123
123
|
} catch (e: any) {
|
|
124
|
-
throw new Error(
|
|
125
|
-
"Invalid request, couldn't parse tree_size or leaf_index"
|
|
126
|
-
);
|
|
124
|
+
throw new Error("Invalid request, couldn't parse tree_size or leaf_index");
|
|
127
125
|
}
|
|
128
126
|
|
|
129
127
|
const mt = this.known_trees.get(hash_hex);
|
|
@@ -136,17 +134,12 @@ export class GetMerkleLeafProofCommand extends ClientCommand {
|
|
|
136
134
|
}
|
|
137
135
|
|
|
138
136
|
if (this.queue.length != 0) {
|
|
139
|
-
throw Error(
|
|
140
|
-
"This command should not execute when the queue is not empty."
|
|
141
|
-
);
|
|
137
|
+
throw Error("This command should not execute when the queue is not empty.");
|
|
142
138
|
}
|
|
143
139
|
|
|
144
140
|
const proof = mt.getProof(leaf_index);
|
|
145
141
|
|
|
146
|
-
const n_response_elements = Math.min(
|
|
147
|
-
Math.floor((255 - 32 - 1 - 1) / 32),
|
|
148
|
-
proof.length
|
|
149
|
-
);
|
|
142
|
+
const n_response_elements = Math.min(Math.floor((255 - 32 - 1 - 1) / 32), proof.length);
|
|
150
143
|
const n_leftover_elements = proof.length - n_response_elements;
|
|
151
144
|
|
|
152
145
|
// Add to the queue any proof elements that do not fit the response
|
|
@@ -196,9 +189,7 @@ export class GetMerkleLeafIndexCommand extends ClientCommand {
|
|
|
196
189
|
|
|
197
190
|
const mt = this.known_trees.get(root_hash_hex);
|
|
198
191
|
if (!mt) {
|
|
199
|
-
throw Error(
|
|
200
|
-
`Requested Merkle leaf index for unknown root: ${root_hash_hex}`
|
|
201
|
-
);
|
|
192
|
+
throw Error(`Requested Merkle leaf index for unknown root: ${root_hash_hex}`);
|
|
202
193
|
}
|
|
203
194
|
|
|
204
195
|
let leaf_index = 0;
|
|
@@ -235,9 +226,9 @@ export class GetMoreElementsCommand extends ClientCommand {
|
|
|
235
226
|
|
|
236
227
|
// all elements should have the same length
|
|
237
228
|
const element_len = this.queue[0].length;
|
|
238
|
-
if (this.queue.some(
|
|
229
|
+
if (this.queue.some(el => el.length != element_len)) {
|
|
239
230
|
throw new Error(
|
|
240
|
-
"The queue contains elements with different byte length, which is not expected"
|
|
231
|
+
"The queue contains elements with different byte length, which is not expected",
|
|
241
232
|
);
|
|
242
233
|
}
|
|
243
234
|
|
|
@@ -309,7 +300,7 @@ export class ClientCommandInterpreter {
|
|
|
309
300
|
const preimage = Buffer.concat([Buffer.from([0]), el]);
|
|
310
301
|
this.addKnownPreimage(preimage);
|
|
311
302
|
}
|
|
312
|
-
const mt = new Merkle(elements.map(
|
|
303
|
+
const mt = new Merkle(elements.map(el => hashLeaf(el)));
|
|
313
304
|
this.roots.set(mt.getRoot().toString("hex"), mt);
|
|
314
305
|
}
|
|
315
306
|
|
|
@@ -24,22 +24,14 @@ export class MerkelizedPsbt extends PsbtV2 {
|
|
|
24
24
|
this.globalMerkleMap = MerkelizedPsbt.createMerkleMap(this.globalMap);
|
|
25
25
|
|
|
26
26
|
for (let i = 0; i < this.getGlobalInputCount(); i++) {
|
|
27
|
-
this.inputMerkleMaps.push(
|
|
28
|
-
MerkelizedPsbt.createMerkleMap(this.inputMaps[i])
|
|
29
|
-
);
|
|
27
|
+
this.inputMerkleMaps.push(MerkelizedPsbt.createMerkleMap(this.inputMaps[i]));
|
|
30
28
|
}
|
|
31
|
-
this.inputMapCommitments = [...this.inputMerkleMaps.values()].map(
|
|
32
|
-
v.commitment()
|
|
33
|
-
);
|
|
29
|
+
this.inputMapCommitments = [...this.inputMerkleMaps.values()].map(v => v.commitment());
|
|
34
30
|
|
|
35
31
|
for (let i = 0; i < this.getGlobalOutputCount(); i++) {
|
|
36
|
-
this.outputMerkleMaps.push(
|
|
37
|
-
MerkelizedPsbt.createMerkleMap(this.outputMaps[i])
|
|
38
|
-
);
|
|
32
|
+
this.outputMerkleMaps.push(MerkelizedPsbt.createMerkleMap(this.outputMaps[i]));
|
|
39
33
|
}
|
|
40
|
-
this.outputMapCommitments = [...this.outputMerkleMaps.values()].map(
|
|
41
|
-
v.commitment()
|
|
42
|
-
);
|
|
34
|
+
this.outputMapCommitments = [...this.outputMerkleMaps.values()].map(v => v.commitment());
|
|
43
35
|
}
|
|
44
36
|
// These public functions are for MerkelizedPsbt.
|
|
45
37
|
getGlobalSize(): number {
|
|
@@ -51,14 +43,14 @@ export class MerkelizedPsbt extends PsbtV2 {
|
|
|
51
43
|
|
|
52
44
|
private static createMerkleMap(map: Map<string, Buffer>): MerkleMap {
|
|
53
45
|
const sortedKeysStrings = [...map.keys()].sort();
|
|
54
|
-
const values = sortedKeysStrings.map(
|
|
46
|
+
const values = sortedKeysStrings.map(k => {
|
|
55
47
|
const v = map.get(k);
|
|
56
48
|
if (!v) {
|
|
57
49
|
throw new Error("No value for key " + k);
|
|
58
50
|
}
|
|
59
51
|
return v;
|
|
60
52
|
});
|
|
61
|
-
const sortedKeys = sortedKeysStrings.map(
|
|
53
|
+
const sortedKeys = sortedKeysStrings.map(k => Buffer.from(k, "hex"));
|
|
62
54
|
|
|
63
55
|
const merkleMap = new MerkleMap(sortedKeys, values);
|
|
64
56
|
return merkleMap;
|
package/src/newops/merkle.ts
CHANGED
|
@@ -10,10 +10,7 @@ export class Merkle {
|
|
|
10
10
|
private rootNode: Node;
|
|
11
11
|
private leafNodes: Node[];
|
|
12
12
|
private h: (buf: Buffer) => Buffer;
|
|
13
|
-
constructor(
|
|
14
|
-
leaves: Buffer[],
|
|
15
|
-
hasher: (buf: Buffer) => Buffer = crypto.sha256
|
|
16
|
-
) {
|
|
13
|
+
constructor(leaves: Buffer[], hasher: (buf: Buffer) => Buffer = crypto.sha256) {
|
|
17
14
|
this.leaves = leaves;
|
|
18
15
|
this.h = hasher;
|
|
19
16
|
const nodes = this.calculateRoot(leaves);
|
|
@@ -68,16 +65,12 @@ export class Merkle {
|
|
|
68
65
|
|
|
69
66
|
export function hashLeaf(
|
|
70
67
|
buf: Buffer,
|
|
71
|
-
hashFunction: (buf: Buffer) => Buffer = crypto.sha256
|
|
68
|
+
hashFunction: (buf: Buffer) => Buffer = crypto.sha256,
|
|
72
69
|
): Buffer {
|
|
73
70
|
return hashConcat(Buffer.from([0]), buf, hashFunction);
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
function hashConcat(
|
|
77
|
-
bufA: Buffer,
|
|
78
|
-
bufB: Buffer,
|
|
79
|
-
hashFunction: (buf: Buffer) => Buffer
|
|
80
|
-
): Buffer {
|
|
73
|
+
function hashConcat(bufA: Buffer, bufB: Buffer, hashFunction: (buf: Buffer) => Buffer): Buffer {
|
|
81
74
|
return hashFunction(Buffer.concat([bufA, bufB]));
|
|
82
75
|
}
|
|
83
76
|
|
package/src/newops/merkleMap.ts
CHANGED
|
@@ -33,9 +33,9 @@ export class MerkleMap {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
this.keys = keys;
|
|
36
|
-
this.keysTree = new Merkle(keys.map(
|
|
36
|
+
this.keysTree = new Merkle(keys.map(k => hashLeaf(k)));
|
|
37
37
|
this.values = values;
|
|
38
|
-
this.valuesTree = new Merkle(values.map(
|
|
38
|
+
this.valuesTree = new Merkle(values.map(v => hashLeaf(v)));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
commitment(): Buffer {
|