@ledgerhq/hw-app-btc 6.27.1 → 6.27.2-nightly.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 (48) hide show
  1. package/.turbo/turbo-build.log +6 -0
  2. package/CHANGELOG.md +10 -0
  3. package/jest.config.ts +6 -0
  4. package/lib/bip32.d.ts.map +1 -1
  5. package/lib/bip32.js.map +1 -1
  6. package/lib/getTrustedInput.d.ts.map +1 -1
  7. package/lib/getTrustedInput.js.map +1 -1
  8. package/lib/newops/appClient.d.ts.map +1 -1
  9. package/lib/newops/appClient.js +1 -4
  10. package/lib/newops/appClient.js.map +1 -1
  11. package/lib/newops/psbtv2.d.ts.map +1 -1
  12. package/lib/newops/psbtv2.js.map +1 -1
  13. package/lib-es/bip32.d.ts.map +1 -1
  14. package/lib-es/bip32.js.map +1 -1
  15. package/lib-es/getTrustedInput.d.ts.map +1 -1
  16. package/lib-es/getTrustedInput.js.map +1 -1
  17. package/lib-es/newops/appClient.d.ts.map +1 -1
  18. package/lib-es/newops/appClient.js +1 -4
  19. package/lib-es/newops/appClient.js.map +1 -1
  20. package/lib-es/newops/psbtv2.d.ts.map +1 -1
  21. package/lib-es/newops/psbtv2.js.map +1 -1
  22. package/package.json +16 -7
  23. package/src/bip32.ts +5 -3
  24. package/src/getTrustedInput.ts +2 -8
  25. package/src/newops/appClient.ts +8 -4
  26. package/src/newops/psbtv2.ts +13 -9
  27. package/LICENSE +0 -202
  28. package/lib-es/Btc.js.flow +0 -280
  29. package/lib-es/bip32.js.flow +0 -13
  30. package/lib-es/compressPublicKey.js.flow +0 -8
  31. package/lib-es/constants.js.flow +0 -13
  32. package/lib-es/createTransaction.js.flow +0 -419
  33. package/lib-es/debug.js.flow +0 -41
  34. package/lib-es/finalizeInput.js.flow +0 -38
  35. package/lib-es/getAppAndVersion.js.flow +0 -19
  36. package/lib-es/getTrustedInput.js.flow +0 -163
  37. package/lib-es/getTrustedInputBIP143.js.flow +0 -37
  38. package/lib-es/getWalletPublicKey.js.flow +0 -51
  39. package/lib-es/hashPublicKey.js.flow +0 -8
  40. package/lib-es/serializeTransaction.js.flow +0 -77
  41. package/lib-es/shouldUseTrustedInputForSegwit.js.flow +0 -15
  42. package/lib-es/signMessage.js.flow +0 -67
  43. package/lib-es/signP2SHTransaction.js.flow +0 -170
  44. package/lib-es/signTransaction.js.flow +0 -40
  45. package/lib-es/splitTransaction.js.flow +0 -145
  46. package/lib-es/startUntrustedHashTransactionInput.js.flow +0 -136
  47. package/lib-es/types.js.flow +0 -31
  48. package/lib-es/varint.js.flow +0 -43
@@ -1,136 +0,0 @@
1
- // @flow
2
- import type Transport from "@ledgerhq/hw-transport";
3
- import type { Transaction } from "./types";
4
- import { createVarint } from "./varint";
5
- import { MAX_SCRIPT_BLOCK } from "./constants";
6
-
7
- export function startUntrustedHashTransactionInputRaw(
8
- transport: Transport<*>,
9
- newTransaction: boolean,
10
- firstRound: boolean,
11
- transactionData: Buffer,
12
- bip143?: boolean = false,
13
- overwinter?: boolean = false,
14
- additionals: Array<string> = []
15
- ) {
16
- const p2 = additionals.includes("cashaddr")
17
- ? 0x03
18
- : bip143
19
- ? additionals.includes("sapling")
20
- ? 0x05
21
- : overwinter
22
- ? 0x04
23
- : 0x02
24
- : 0x00;
25
- return transport.send(
26
- 0xe0,
27
- 0x44,
28
- firstRound ? 0x00 : 0x80,
29
- newTransaction ? p2 : 0x80,
30
- transactionData
31
- );
32
- }
33
-
34
- export async function startUntrustedHashTransactionInput(
35
- transport: Transport<*>,
36
- newTransaction: boolean,
37
- transaction: Transaction,
38
- inputs: Array<{ trustedInput: boolean, value: Buffer }>,
39
- bip143?: boolean = false,
40
- overwinter?: boolean = false,
41
- additionals: Array<string> = [],
42
- useTrustedInputForSegwit?: boolean = false
43
- ) {
44
- let data = Buffer.concat([
45
- transaction.version,
46
- transaction.timestamp || Buffer.alloc(0),
47
- transaction.nVersionGroupId || Buffer.alloc(0),
48
- createVarint(transaction.inputs.length),
49
- ]);
50
-
51
- await startUntrustedHashTransactionInputRaw(
52
- transport,
53
- newTransaction,
54
- true,
55
- data,
56
- bip143,
57
- overwinter,
58
- additionals
59
- );
60
-
61
- let i = 0;
62
- const isDecred = additionals.includes("decred");
63
-
64
- for (let input of transaction.inputs) {
65
- let prefix;
66
- let inputValue = inputs[i].value;
67
- if (bip143) {
68
- if (useTrustedInputForSegwit && inputs[i].trustedInput) {
69
- prefix = Buffer.from([0x01, inputValue.length]);
70
- } else {
71
- prefix = Buffer.from([0x02]);
72
- }
73
- } else {
74
- if (inputs[i].trustedInput) {
75
- prefix = Buffer.from([0x01, inputs[i].value.length]);
76
- } else {
77
- prefix = Buffer.from([0x00]);
78
- }
79
- }
80
- data = Buffer.concat([
81
- prefix,
82
- inputValue,
83
- isDecred ? Buffer.from([0x00]) : Buffer.alloc(0),
84
- createVarint(input.script.length),
85
- ]);
86
-
87
- await startUntrustedHashTransactionInputRaw(
88
- transport,
89
- newTransaction,
90
- false,
91
- data,
92
- bip143,
93
- overwinter,
94
- additionals
95
- );
96
-
97
- let scriptBlocks = [];
98
- let offset = 0;
99
-
100
- if (input.script.length === 0) {
101
- scriptBlocks.push(input.sequence);
102
- } else {
103
- while (offset !== input.script.length) {
104
- let blockSize =
105
- input.script.length - offset > MAX_SCRIPT_BLOCK
106
- ? MAX_SCRIPT_BLOCK
107
- : input.script.length - offset;
108
- if (offset + blockSize !== input.script.length) {
109
- scriptBlocks.push(input.script.slice(offset, offset + blockSize));
110
- } else {
111
- scriptBlocks.push(
112
- Buffer.concat([
113
- input.script.slice(offset, offset + blockSize),
114
- input.sequence,
115
- ])
116
- );
117
- }
118
- offset += blockSize;
119
- }
120
- }
121
-
122
- for (let scriptBlock of scriptBlocks) {
123
- await startUntrustedHashTransactionInputRaw(
124
- transport,
125
- newTransaction,
126
- false,
127
- scriptBlock,
128
- bip143,
129
- overwinter,
130
- additionals
131
- );
132
- }
133
-
134
- i++;
135
- }
136
- }
@@ -1,31 +0,0 @@
1
- // @flow
2
-
3
- /**
4
- */
5
- export type TransactionInput = {
6
- prevout: Buffer,
7
- script: Buffer,
8
- sequence: Buffer,
9
- tree?: Buffer,
10
- };
11
-
12
- /**
13
- */
14
- export type TransactionOutput = {
15
- amount: Buffer,
16
- script: Buffer,
17
- };
18
-
19
- /**
20
- */
21
- export type Transaction = {
22
- version: Buffer,
23
- inputs: TransactionInput[],
24
- outputs?: TransactionOutput[],
25
- locktime?: Buffer,
26
- witness?: Buffer,
27
- timestamp?: Buffer,
28
- nVersionGroupId?: Buffer,
29
- nExpiryHeight?: Buffer,
30
- extraData?: Buffer,
31
- };
@@ -1,43 +0,0 @@
1
- // @flow
2
-
3
- export function getVarint(data: Buffer, offset: number): [number, number] {
4
- if (data[offset] < 0xfd) {
5
- return [data[offset], 1];
6
- }
7
- if (data[offset] === 0xfd) {
8
- return [(data[offset + 2] << 8) + data[offset + 1], 3];
9
- }
10
- if (data[offset] === 0xfe) {
11
- return [
12
- (data[offset + 4] << 24) +
13
- (data[offset + 3] << 16) +
14
- (data[offset + 2] << 8) +
15
- data[offset + 1],
16
- 5,
17
- ];
18
- }
19
-
20
- throw new Error("getVarint called with unexpected parameters");
21
- }
22
-
23
- export function createVarint(value: number): Buffer {
24
- if (value < 0xfd) {
25
- const buffer = Buffer.alloc(1);
26
- buffer[0] = value;
27
- return buffer;
28
- }
29
- if (value <= 0xffff) {
30
- const buffer = Buffer.alloc(3);
31
- buffer[0] = 0xfd;
32
- buffer[1] = value & 0xff;
33
- buffer[2] = (value >> 8) & 0xff;
34
- return buffer;
35
- }
36
- const buffer = Buffer.alloc(5);
37
- buffer[0] = 0xfe;
38
- buffer[1] = value & 0xff;
39
- buffer[2] = (value >> 8) & 0xff;
40
- buffer[3] = (value >> 16) & 0xff;
41
- buffer[4] = (value >> 24) & 0xff;
42
- return buffer;
43
- }