@ledgerhq/hw-app-str 6.29.0-nightly.3 → 8.0.0-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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +15 -26
- package/README.md +161 -57
- package/lib/Str.d.ts +43 -18
- package/lib/Str.d.ts.map +1 -1
- package/lib/Str.js +166 -175
- package/lib/Str.js.map +1 -1
- package/lib/errors.d.ts +27 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +23 -0
- package/lib/errors.js.map +1 -0
- package/lib-es/Str.d.ts +43 -18
- package/lib-es/Str.d.ts.map +1 -1
- package/lib-es/Str.js +149 -175
- package/lib-es/Str.js.map +1 -1
- package/lib-es/errors.d.ts +27 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +20 -0
- package/lib-es/errors.js.map +1 -0
- package/package.json +5 -5
- package/src/Str.ts +168 -234
- package/src/errors.ts +27 -0
- package/tests/Str.test.ts +322 -17
- package/lib/utils.d.ts +0 -9
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -106
- package/lib/utils.js.map +0 -1
- package/lib-es/utils.d.ts +0 -9
- package/lib-es/utils.d.ts.map +0 -1
- package/lib-es/utils.js +0 -93
- package/lib-es/utils.js.map +0 -1
- package/src/utils.ts +0 -111
package/src/utils.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Ledger Node JS API
|
|
3
|
-
* (c) 2017-2018 Ledger
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
********************************************************************************/
|
|
17
|
-
import base32 from "base32.js";
|
|
18
|
-
import nacl from "tweetnacl";
|
|
19
|
-
import { sha256 } from "sha.js";
|
|
20
|
-
// TODO use bip32-path library
|
|
21
|
-
export function splitPath(path: string): number[] {
|
|
22
|
-
const result: number[] = [];
|
|
23
|
-
const components = path.split("/");
|
|
24
|
-
components.forEach(element => {
|
|
25
|
-
let number = parseInt(element, 10);
|
|
26
|
-
|
|
27
|
-
if (isNaN(number)) {
|
|
28
|
-
return; // FIXME shouldn't it throws instead?
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (element.length > 1 && element[element.length - 1] === "'") {
|
|
32
|
-
number += 0x80000000;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
result.push(number);
|
|
36
|
-
});
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
export function foreach<T, A>(
|
|
40
|
-
arr: T[],
|
|
41
|
-
callback: (arg0: T, arg1: number) => Promise<A>,
|
|
42
|
-
): Promise<A[]> {
|
|
43
|
-
function iterate(index, array, result) {
|
|
44
|
-
if (index >= array.length) {
|
|
45
|
-
return result;
|
|
46
|
-
} else {
|
|
47
|
-
return callback(array[index], index).then(function (res) {
|
|
48
|
-
result.push(res);
|
|
49
|
-
return iterate(index + 1, array, result);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return Promise.resolve().then(() => iterate(0, arr, []));
|
|
55
|
-
}
|
|
56
|
-
export function crc16xmodem(buf: Buffer, previous?: number): number {
|
|
57
|
-
let crc = typeof previous !== "undefined" ? ~~previous : 0x0;
|
|
58
|
-
|
|
59
|
-
for (let index = 0; index < buf.length; index++) {
|
|
60
|
-
const byte = buf[index];
|
|
61
|
-
let code = (crc >>> 8) & 0xff;
|
|
62
|
-
code ^= byte & 0xff;
|
|
63
|
-
code ^= code >>> 4;
|
|
64
|
-
crc = (crc << 8) & 0xffff;
|
|
65
|
-
crc ^= code;
|
|
66
|
-
code = (code << 5) & 0xffff;
|
|
67
|
-
crc ^= code;
|
|
68
|
-
code = (code << 7) & 0xffff;
|
|
69
|
-
crc ^= code;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return crc;
|
|
73
|
-
}
|
|
74
|
-
export function encodeEd25519PublicKey(rawPublicKey: Buffer): string {
|
|
75
|
-
const versionByte = 6 << 3; // 'G'
|
|
76
|
-
|
|
77
|
-
const data = Buffer.from(rawPublicKey);
|
|
78
|
-
const versionBuffer = Buffer.from([versionByte]);
|
|
79
|
-
const payload = Buffer.concat([versionBuffer, data]);
|
|
80
|
-
const checksum = Buffer.alloc(2);
|
|
81
|
-
checksum.writeUInt16LE(crc16xmodem(payload), 0);
|
|
82
|
-
const unencoded = Buffer.concat([payload, checksum]);
|
|
83
|
-
return base32.encode(unencoded);
|
|
84
|
-
}
|
|
85
|
-
export function verifyEd25519Signature(
|
|
86
|
-
data: Buffer,
|
|
87
|
-
signature: Buffer,
|
|
88
|
-
publicKey: Buffer,
|
|
89
|
-
): boolean {
|
|
90
|
-
return nacl.sign.detached.verify(
|
|
91
|
-
new Uint8Array(data.toJSON().data),
|
|
92
|
-
new Uint8Array(signature.toJSON().data),
|
|
93
|
-
new Uint8Array(publicKey.toJSON().data),
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
export function hash(data: Buffer) {
|
|
97
|
-
const hasher = new sha256();
|
|
98
|
-
hasher.update(data, "utf8");
|
|
99
|
-
return hasher.digest();
|
|
100
|
-
}
|
|
101
|
-
export function checkStellarBip32Path(path: string): void {
|
|
102
|
-
path.split("/").forEach(function (element) {
|
|
103
|
-
if (!element.toString().endsWith("'")) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
"Detected a non-hardened path element in requested BIP32 path." +
|
|
106
|
-
" Non-hardended paths are not supported at this time. Please use an all-hardened path." +
|
|
107
|
-
" Example: 44'/148'/0'",
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|