pretty
This commit is contained in:
parent
2caef6dcf2
commit
5d31803c92
@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
const NOOP = () => { };
|
||||
const NOOP = () => {};
|
||||
|
||||
/**
|
||||
* A token that can be passed around to inform consumers of the token that a
|
||||
@ -136,7 +136,7 @@ class CancellationToken {
|
||||
* Whether the token can be cancelled.
|
||||
*/
|
||||
private _canBeCancelled: boolean,
|
||||
) { }
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Create a {CancellationTokenSource}.
|
||||
|
@ -21,7 +21,6 @@ import { AbsoluteTime } from "./time.js";
|
||||
* Implementation of token bucket throttling.
|
||||
*/
|
||||
|
||||
|
||||
const logger = new Logger("RequestThrottler.ts");
|
||||
|
||||
/**
|
||||
|
@ -448,7 +448,7 @@ export class Amounts {
|
||||
/**
|
||||
* Number of fractional digits needed to fully represent the amount
|
||||
* @param a amount
|
||||
* @returns
|
||||
* @returns
|
||||
*/
|
||||
static maxFractionalDigits(a: AmountJson): number {
|
||||
if (a.fraction === 0) return 0;
|
||||
@ -466,6 +466,4 @@ export class Amounts {
|
||||
}
|
||||
return amountFractionalLength - i + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
var CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
|
||||
var CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
||||
var GENERATOR = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];
|
||||
|
||||
const encodings: any = {
|
||||
@ -38,7 +38,7 @@ function getEncodingConst(enc: any) {
|
||||
} else if (enc == encodings.BECH32M) {
|
||||
return 0x2bc830a3;
|
||||
} else {
|
||||
throw new Error('unknown encoding')
|
||||
throw new Error("unknown encoding");
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ function polymod(values: any) {
|
||||
var chk = 1;
|
||||
for (var p = 0; p < values.length; ++p) {
|
||||
var top = chk >> 25;
|
||||
chk = (chk & 0x1ffffff) << 5 ^ values[p];
|
||||
chk = ((chk & 0x1ffffff) << 5) ^ values[p];
|
||||
for (var i = 0; i < 5; ++i) {
|
||||
if ((top >> i) & 1) {
|
||||
chk ^= GENERATOR[i];
|
||||
@ -78,14 +78,14 @@ function createChecksum(hrp: any, data: any, enc: any) {
|
||||
var mod = polymod(values) ^ getEncodingConst(enc);
|
||||
var ret = [];
|
||||
for (var p = 0; p < 6; ++p) {
|
||||
ret.push((mod >> 5 * (5 - p)) & 31);
|
||||
ret.push((mod >> (5 * (5 - p))) & 31);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function encode(hrp: any, data: any, enc: any): string {
|
||||
var combined = data.concat(createChecksum(hrp, data, enc));
|
||||
var ret = hrp + '1';
|
||||
var ret = hrp + "1";
|
||||
for (var p = 0; p < combined.length; ++p) {
|
||||
ret += CHARSET.charAt(combined[p]);
|
||||
}
|
||||
@ -111,7 +111,7 @@ function decode(bechString: any, enc: any) {
|
||||
return null;
|
||||
}
|
||||
bechString = bechString.toLowerCase();
|
||||
var pos = bechString.lastIndexOf('1');
|
||||
var pos = bechString.lastIndexOf("1");
|
||||
if (pos < 1 || pos + 7 > bechString.length || bechString.length > 90) {
|
||||
return null;
|
||||
}
|
||||
@ -128,4 +128,4 @@ function decode(bechString: any, enc: any) {
|
||||
return null;
|
||||
}
|
||||
return { hrp: hrp, data: data.slice(0, data.length - 6) };
|
||||
}
|
||||
}
|
||||
|
@ -19,59 +19,90 @@
|
||||
*/
|
||||
|
||||
import test from "ava";
|
||||
import {
|
||||
generateFakeSegwitAddress,
|
||||
} from "./bitcoin.js";
|
||||
import { generateFakeSegwitAddress } from "./bitcoin.js";
|
||||
|
||||
test("generate testnet", (t) => {
|
||||
const [addr1, addr2] = generateFakeSegwitAddress("B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSG", "tb1qhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
const [addr1, addr2] = generateFakeSegwitAddress(
|
||||
"B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSG",
|
||||
"tb1qhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
|
||||
t.assert(addr1 === "tb1qtfwqwaj6tsrhdtvuyhflr6nklm8ldqxpf0lfjw");
|
||||
t.assert(addr2 === "tb1qmfwqwa5vr5vdac6wr20ts76aewakzpmns40yuf");
|
||||
});
|
||||
|
||||
test("generate mainnet", (t) => {
|
||||
const [addr1, addr2] = generateFakeSegwitAddress("B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSG", "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq")
|
||||
const [addr1, addr2] = generateFakeSegwitAddress(
|
||||
"B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSG",
|
||||
"bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq",
|
||||
);
|
||||
//bc
|
||||
t.assert(addr1 === "bc1qtfwqwaj6tsrhdtvuyhflr6nklm8ldqxprfy6fa");
|
||||
t.assert(addr2 === "bc1qmfwqwa5vr5vdac6wr20ts76aewakzpmn6n5h86");
|
||||
});
|
||||
|
||||
test("generate Regtest", (t) => {
|
||||
const [addr1, addr2] = generateFakeSegwitAddress("B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSG", "bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
const [addr1, addr2] = generateFakeSegwitAddress(
|
||||
"B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSG",
|
||||
"bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
|
||||
t.assert(addr1 === "bcrt1qtfwqwaj6tsrhdtvuyhflr6nklm8ldqxptxxy98");
|
||||
t.assert(addr2 === "bcrt1qmfwqwa5vr5vdac6wr20ts76aewakzpmnjukftq");
|
||||
});
|
||||
|
||||
|
||||
test("unknown net", (t) => {
|
||||
t.throws(() => {
|
||||
generateFakeSegwitAddress("B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSG", "abqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
})
|
||||
|
||||
generateFakeSegwitAddress(
|
||||
"B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSG",
|
||||
"abqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("invalid or no reserve", (t) => {
|
||||
let result = undefined;
|
||||
// empty
|
||||
result = generateFakeSegwitAddress("", "bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
t.deepEqual(result, [])
|
||||
// small
|
||||
result = generateFakeSegwitAddress("s", "bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
t.deepEqual(result, [])
|
||||
result = generateFakeSegwitAddress("asdsad", "bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
t.deepEqual(result, [])
|
||||
result = generateFakeSegwitAddress("asdasdasdasdasdasd", "bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
t.deepEqual(result, [])
|
||||
result = generateFakeSegwitAddress("B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XS", "bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
t.deepEqual(result, [])
|
||||
result = generateFakeSegwitAddress("B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSSSS", "bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
t.deepEqual(result, [])
|
||||
// empty
|
||||
result = generateFakeSegwitAddress(
|
||||
"",
|
||||
"bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
t.deepEqual(result, []);
|
||||
// small
|
||||
result = generateFakeSegwitAddress(
|
||||
"s",
|
||||
"bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
t.deepEqual(result, []);
|
||||
result = generateFakeSegwitAddress(
|
||||
"asdsad",
|
||||
"bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
t.deepEqual(result, []);
|
||||
result = generateFakeSegwitAddress(
|
||||
"asdasdasdasdasdasd",
|
||||
"bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
t.deepEqual(result, []);
|
||||
result = generateFakeSegwitAddress(
|
||||
"B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XS",
|
||||
"bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
t.deepEqual(result, []);
|
||||
result = generateFakeSegwitAddress(
|
||||
"B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XSSSS",
|
||||
"bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
t.deepEqual(result, []);
|
||||
// no reserve
|
||||
result = generateFakeSegwitAddress(undefined, "bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
t.deepEqual(result, [])
|
||||
result = generateFakeSegwitAddress("B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XS-", "bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v")
|
||||
t.deepEqual(result, [])
|
||||
result = generateFakeSegwitAddress(
|
||||
undefined,
|
||||
"bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
t.deepEqual(result, []);
|
||||
result = generateFakeSegwitAddress(
|
||||
"B9E0EXNDKGJX7WFAEVZCZXM0R661T66YWD71N7NRFDEWQEV10XS-",
|
||||
"bcrtqhxrhccqexg0dv4nltgkuw4fg2ce7muplmjsn0v",
|
||||
);
|
||||
t.deepEqual(result, []);
|
||||
});
|
||||
|
||||
|
@ -26,7 +26,6 @@ import { AmountJson, Amounts } from "./amounts.js";
|
||||
import { decodeCrock } from "./talerCrypto.js";
|
||||
import * as segwit from "./segwit_addr.js";
|
||||
|
||||
|
||||
function buf2hex(buffer: Uint8Array) {
|
||||
// buffer is an ArrayBuffer
|
||||
return [...new Uint8Array(buffer)]
|
||||
@ -35,24 +34,23 @@ function buf2hex(buffer: Uint8Array) {
|
||||
}
|
||||
|
||||
const hext2buf = (hexString: string) =>
|
||||
new Uint8Array(hexString.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16)));
|
||||
|
||||
new Uint8Array(hexString.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)));
|
||||
|
||||
export function generateFakeSegwitAddress(
|
||||
reservePub: string | undefined,
|
||||
addr: string
|
||||
addr: string,
|
||||
): string[] {
|
||||
if (!reservePub) return []
|
||||
if (!reservePub) return [];
|
||||
let pub;
|
||||
try {
|
||||
pub = decodeCrock(reservePub);
|
||||
} catch {
|
||||
// pub = new Uint8Array(0)
|
||||
}
|
||||
if (!pub || pub.length !== 32) return []
|
||||
if (!pub || pub.length !== 32) return [];
|
||||
|
||||
const first_rnd = new Uint8Array(4);
|
||||
first_rnd.set(pub.subarray(0, 4))
|
||||
first_rnd.set(pub.subarray(0, 4));
|
||||
const second_rnd = new Uint8Array(4);
|
||||
second_rnd.set(pub.subarray(0, 4));
|
||||
|
||||
@ -71,16 +69,16 @@ export function generateFakeSegwitAddress(
|
||||
addr[0] === "t" && addr[1] == "b"
|
||||
? "tb"
|
||||
: addr[0] === "b" && addr[1] == "c" && addr[2] === "r" && addr[3] == "t"
|
||||
? "bcrt"
|
||||
: addr[0] === "b" && addr[1] == "c"
|
||||
? "bc"
|
||||
: undefined;
|
||||
? "bcrt"
|
||||
: addr[0] === "b" && addr[1] == "c"
|
||||
? "bc"
|
||||
: undefined;
|
||||
if (prefix === undefined) throw new Error("unknown bitcoin net");
|
||||
|
||||
const addr1 = segwit.default.encode(prefix, 0, first_part);
|
||||
const addr2 = segwit.default.encode(prefix, 0, second_part);
|
||||
|
||||
return [addr1, addr2]
|
||||
return [addr1, addr2];
|
||||
}
|
||||
|
||||
// https://github.com/bitcoin/bitcoin/blob/master/src/policy/policy.cpp
|
||||
|
@ -134,7 +134,7 @@ class UnionCodecBuilder<
|
||||
TargetType,
|
||||
TagPropertyLabel extends keyof TargetType,
|
||||
CommonBaseType,
|
||||
PartialTargetType
|
||||
PartialTargetType,
|
||||
> {
|
||||
private alternatives = new Map<any, Alternative>();
|
||||
|
||||
|
@ -27,11 +27,7 @@ import {
|
||||
|
||||
const logger = new Logger("contractTerms.ts");
|
||||
|
||||
|
||||
|
||||
|
||||
export namespace ContractTermsUtil {
|
||||
|
||||
export function forgetAllImpl(
|
||||
anyJson: any,
|
||||
path: string[],
|
||||
@ -76,7 +72,6 @@ export namespace ContractTermsUtil {
|
||||
return dup;
|
||||
}
|
||||
|
||||
|
||||
export type PathPredicate = (path: string[]) => boolean;
|
||||
|
||||
/**
|
||||
|
@ -35,4 +35,4 @@ export namespace fnutil {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export function setupI18n(lang: string, strings: { [s: string]: any }): any {
|
||||
lang = lang.replace("_", "-");
|
||||
|
||||
if (!strings[lang]) {
|
||||
strings[lang] = {}
|
||||
strings[lang] = {};
|
||||
// logger.warn(`language ${lang} not found, defaulting to source strings`);
|
||||
}
|
||||
jed = new jedLib.Jed(strings[lang]);
|
||||
@ -45,7 +45,10 @@ function toI18nString(stringSeq: ReadonlyArray<string>): string {
|
||||
/**
|
||||
* Internationalize a string template with arbitrary serialized values.
|
||||
*/
|
||||
export function singular(stringSeq: TemplateStringsArray, ...values: any[]): string {
|
||||
export function singular(
|
||||
stringSeq: TemplateStringsArray,
|
||||
...values: any[]
|
||||
): string {
|
||||
const s = toI18nString(stringSeq);
|
||||
const tr = jed
|
||||
.translate(s)
|
||||
@ -70,13 +73,19 @@ export function translate(
|
||||
/**
|
||||
* Internationalize a string template without serializing
|
||||
*/
|
||||
export function Translate({ children, debug, }: { children: any, debug?: boolean }): any {
|
||||
export function Translate({
|
||||
children,
|
||||
debug,
|
||||
}: {
|
||||
children: any;
|
||||
debug?: boolean;
|
||||
}): any {
|
||||
const c = [].concat(children);
|
||||
const s = stringifyArray(c);
|
||||
if (!s) return [];
|
||||
const translation: string = jed.ngettext(s, s, 1);
|
||||
if (debug) {
|
||||
console.log("looking for ", s, "got", translation)
|
||||
console.log("looking for ", s, "got", translation);
|
||||
}
|
||||
return replacePlaceholderWithValues(translation, c);
|
||||
}
|
||||
@ -148,4 +157,3 @@ export const i18n = {
|
||||
Translate,
|
||||
translate,
|
||||
};
|
||||
|
||||
|
24
packages/taler-util/src/kdf.d.ts
vendored
24
packages/taler-util/src/kdf.d.ts
vendored
@ -1,5 +1,21 @@
|
||||
export declare function sha512(data: Uint8Array): Uint8Array;
|
||||
export declare function hmac(digest: (d: Uint8Array) => Uint8Array, blockSize: number, key: Uint8Array, message: Uint8Array): Uint8Array;
|
||||
export declare function hmacSha512(key: Uint8Array, message: Uint8Array): Uint8Array;
|
||||
export declare function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array;
|
||||
export declare function kdf(outputLength: number, ikm: Uint8Array, salt: Uint8Array, info: Uint8Array): Uint8Array;
|
||||
export declare function hmac(
|
||||
digest: (d: Uint8Array) => Uint8Array,
|
||||
blockSize: number,
|
||||
key: Uint8Array,
|
||||
message: Uint8Array,
|
||||
): Uint8Array;
|
||||
export declare function hmacSha512(
|
||||
key: Uint8Array,
|
||||
message: Uint8Array,
|
||||
): Uint8Array;
|
||||
export declare function hmacSha256(
|
||||
key: Uint8Array,
|
||||
message: Uint8Array,
|
||||
): Uint8Array;
|
||||
export declare function kdf(
|
||||
outputLength: number,
|
||||
ikm: Uint8Array,
|
||||
salt: Uint8Array,
|
||||
info: Uint8Array,
|
||||
): Uint8Array;
|
||||
|
@ -16,61 +16,60 @@
|
||||
import * as nacl from "./nacl-fast.js";
|
||||
import { sha256 } from "./sha256.js";
|
||||
export function sha512(data) {
|
||||
return nacl.hash(data);
|
||||
return nacl.hash(data);
|
||||
}
|
||||
export function hmac(digest, blockSize, key, message) {
|
||||
if (key.byteLength > blockSize) {
|
||||
key = digest(key);
|
||||
}
|
||||
if (key.byteLength < blockSize) {
|
||||
const k = key;
|
||||
key = new Uint8Array(blockSize);
|
||||
key.set(k, 0);
|
||||
}
|
||||
const okp = new Uint8Array(blockSize);
|
||||
const ikp = new Uint8Array(blockSize);
|
||||
for (let i = 0; i < blockSize; i++) {
|
||||
ikp[i] = key[i] ^ 0x36;
|
||||
okp[i] = key[i] ^ 0x5c;
|
||||
}
|
||||
const b1 = new Uint8Array(blockSize + message.byteLength);
|
||||
b1.set(ikp, 0);
|
||||
b1.set(message, blockSize);
|
||||
const h0 = digest(b1);
|
||||
const b2 = new Uint8Array(blockSize + h0.length);
|
||||
b2.set(okp, 0);
|
||||
b2.set(h0, blockSize);
|
||||
return digest(b2);
|
||||
if (key.byteLength > blockSize) {
|
||||
key = digest(key);
|
||||
}
|
||||
if (key.byteLength < blockSize) {
|
||||
const k = key;
|
||||
key = new Uint8Array(blockSize);
|
||||
key.set(k, 0);
|
||||
}
|
||||
const okp = new Uint8Array(blockSize);
|
||||
const ikp = new Uint8Array(blockSize);
|
||||
for (let i = 0; i < blockSize; i++) {
|
||||
ikp[i] = key[i] ^ 0x36;
|
||||
okp[i] = key[i] ^ 0x5c;
|
||||
}
|
||||
const b1 = new Uint8Array(blockSize + message.byteLength);
|
||||
b1.set(ikp, 0);
|
||||
b1.set(message, blockSize);
|
||||
const h0 = digest(b1);
|
||||
const b2 = new Uint8Array(blockSize + h0.length);
|
||||
b2.set(okp, 0);
|
||||
b2.set(h0, blockSize);
|
||||
return digest(b2);
|
||||
}
|
||||
export function hmacSha512(key, message) {
|
||||
return hmac(sha512, 128, key, message);
|
||||
return hmac(sha512, 128, key, message);
|
||||
}
|
||||
export function hmacSha256(key, message) {
|
||||
return hmac(sha256, 64, key, message);
|
||||
return hmac(sha256, 64, key, message);
|
||||
}
|
||||
export function kdf(outputLength, ikm, salt, info) {
|
||||
// extract
|
||||
const prk = hmacSha512(salt, ikm);
|
||||
// expand
|
||||
const N = Math.ceil(outputLength / 32);
|
||||
const output = new Uint8Array(N * 32);
|
||||
for (let i = 0; i < N; i++) {
|
||||
let buf;
|
||||
if (i == 0) {
|
||||
buf = new Uint8Array(info.byteLength + 1);
|
||||
buf.set(info, 0);
|
||||
}
|
||||
else {
|
||||
buf = new Uint8Array(info.byteLength + 1 + 32);
|
||||
for (let j = 0; j < 32; j++) {
|
||||
buf[j] = output[(i - 1) * 32 + j];
|
||||
}
|
||||
buf.set(info, 32);
|
||||
}
|
||||
buf[buf.length - 1] = i + 1;
|
||||
const chunk = hmacSha256(prk, buf);
|
||||
output.set(chunk, i * 32);
|
||||
// extract
|
||||
const prk = hmacSha512(salt, ikm);
|
||||
// expand
|
||||
const N = Math.ceil(outputLength / 32);
|
||||
const output = new Uint8Array(N * 32);
|
||||
for (let i = 0; i < N; i++) {
|
||||
let buf;
|
||||
if (i == 0) {
|
||||
buf = new Uint8Array(info.byteLength + 1);
|
||||
buf.set(info, 0);
|
||||
} else {
|
||||
buf = new Uint8Array(info.byteLength + 1 + 32);
|
||||
for (let j = 0; j < 32; j++) {
|
||||
buf[j] = output[(i - 1) * 32 + j];
|
||||
}
|
||||
buf.set(info, 32);
|
||||
}
|
||||
return output.slice(0, outputLength);
|
||||
buf[buf.length - 1] = i + 1;
|
||||
const chunk = hmacSha256(prk, buf);
|
||||
output.set(chunk, i * 32);
|
||||
}
|
||||
return output.slice(0, outputLength);
|
||||
}
|
||||
//# sourceMappingURL=kdf.js.map
|
||||
//# sourceMappingURL=kdf.js.map
|
||||
|
@ -140,16 +140,18 @@ export function parsePaytoUri(s: string): PaytoUri | undefined {
|
||||
};
|
||||
}
|
||||
if (targetType === "bitcoin") {
|
||||
const msg = /\b([A-Z0-9]{52})\b/.exec(params["message"])
|
||||
const msg = /\b([A-Z0-9]{52})\b/.exec(params["message"]);
|
||||
const reserve = !msg ? params["subject"] : msg[0];
|
||||
const segwitAddrs = !reserve ? [] : generateFakeSegwitAddress(reserve, targetPath);
|
||||
const segwitAddrs = !reserve
|
||||
? []
|
||||
: generateFakeSegwitAddress(reserve, targetPath);
|
||||
|
||||
const result: PaytoUriBitcoin = {
|
||||
isKnown: true,
|
||||
targetPath,
|
||||
targetType,
|
||||
params,
|
||||
segwitAddrs
|
||||
segwitAddrs,
|
||||
};
|
||||
|
||||
return result;
|
||||
|
@ -18,21 +18,26 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
import bech32 from "./bech32.js"
|
||||
import bech32 from "./bech32.js";
|
||||
|
||||
export default {
|
||||
encode: encode,
|
||||
decode: decode
|
||||
decode: decode,
|
||||
};
|
||||
|
||||
function convertbits(data: any, frombits: number, tobits: number, pad: boolean): any[] {
|
||||
function convertbits(
|
||||
data: any,
|
||||
frombits: number,
|
||||
tobits: number,
|
||||
pad: boolean,
|
||||
): any[] {
|
||||
var acc = 0;
|
||||
var bits = 0;
|
||||
var ret = [];
|
||||
var maxv = (1 << tobits) - 1;
|
||||
for (var p = 0; p < data.length; ++p) {
|
||||
var value = data[p];
|
||||
if (value < 0 || (value >> frombits) !== 0) {
|
||||
if (value < 0 || value >> frombits !== 0) {
|
||||
return []; //check this, was returning null
|
||||
}
|
||||
acc = (acc << frombits) | value;
|
||||
@ -46,7 +51,7 @@ function convertbits(data: any, frombits: number, tobits: number, pad: boolean):
|
||||
if (bits > 0) {
|
||||
ret.push((acc << (tobits - bits)) & maxv);
|
||||
}
|
||||
} else if (bits >= frombits || ((acc << (tobits - bits)) & maxv)) {
|
||||
} else if (bits >= frombits || (acc << (tobits - bits)) & maxv) {
|
||||
return []; //check this, was returning null
|
||||
}
|
||||
return ret;
|
||||
@ -59,7 +64,12 @@ function decode(hrp: any, addr: string) {
|
||||
dec = bech32.decode(addr, bech32.encodings.BECH32M);
|
||||
bech32m = true;
|
||||
}
|
||||
if (dec === null || dec.hrp !== hrp || dec.data.length < 1 || dec.data[0] > 16) {
|
||||
if (
|
||||
dec === null ||
|
||||
dec.hrp !== hrp ||
|
||||
dec.data.length < 1 ||
|
||||
dec.data[0] > 16
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
var res = convertbits(dec.data.slice(1), 5, 8, false);
|
||||
@ -83,9 +93,13 @@ function encode(hrp: any, version: number, program: any): string {
|
||||
if (version > 0) {
|
||||
enc = bech32.encodings.BECH32M;
|
||||
}
|
||||
var ret = bech32.encode(hrp, [version].concat(convertbits(program, 8, 5, true)), enc);
|
||||
if (decode(hrp, ret/*, enc*/) === null) {
|
||||
var ret = bech32.encode(
|
||||
hrp,
|
||||
[version].concat(convertbits(program, 8, 5, true)),
|
||||
enc,
|
||||
);
|
||||
if (decode(hrp, ret /*, enc*/) === null) {
|
||||
return ""; //check this was returning null
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -16,70 +16,17 @@ export const blockSize = 64;
|
||||
|
||||
// SHA-256 constants
|
||||
const K = new Uint32Array([
|
||||
0x428a2f98,
|
||||
0x71374491,
|
||||
0xb5c0fbcf,
|
||||
0xe9b5dba5,
|
||||
0x3956c25b,
|
||||
0x59f111f1,
|
||||
0x923f82a4,
|
||||
0xab1c5ed5,
|
||||
0xd807aa98,
|
||||
0x12835b01,
|
||||
0x243185be,
|
||||
0x550c7dc3,
|
||||
0x72be5d74,
|
||||
0x80deb1fe,
|
||||
0x9bdc06a7,
|
||||
0xc19bf174,
|
||||
0xe49b69c1,
|
||||
0xefbe4786,
|
||||
0x0fc19dc6,
|
||||
0x240ca1cc,
|
||||
0x2de92c6f,
|
||||
0x4a7484aa,
|
||||
0x5cb0a9dc,
|
||||
0x76f988da,
|
||||
0x983e5152,
|
||||
0xa831c66d,
|
||||
0xb00327c8,
|
||||
0xbf597fc7,
|
||||
0xc6e00bf3,
|
||||
0xd5a79147,
|
||||
0x06ca6351,
|
||||
0x14292967,
|
||||
0x27b70a85,
|
||||
0x2e1b2138,
|
||||
0x4d2c6dfc,
|
||||
0x53380d13,
|
||||
0x650a7354,
|
||||
0x766a0abb,
|
||||
0x81c2c92e,
|
||||
0x92722c85,
|
||||
0xa2bfe8a1,
|
||||
0xa81a664b,
|
||||
0xc24b8b70,
|
||||
0xc76c51a3,
|
||||
0xd192e819,
|
||||
0xd6990624,
|
||||
0xf40e3585,
|
||||
0x106aa070,
|
||||
0x19a4c116,
|
||||
0x1e376c08,
|
||||
0x2748774c,
|
||||
0x34b0bcb5,
|
||||
0x391c0cb3,
|
||||
0x4ed8aa4a,
|
||||
0x5b9cca4f,
|
||||
0x682e6ff3,
|
||||
0x748f82ee,
|
||||
0x78a5636f,
|
||||
0x84c87814,
|
||||
0x8cc70208,
|
||||
0x90befffa,
|
||||
0xa4506ceb,
|
||||
0xbef9a3f7,
|
||||
0xc67178f2,
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
||||
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
||||
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
||||
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
||||
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
||||
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
||||
]);
|
||||
|
||||
function hashBlocks(
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -296,7 +296,7 @@ function normalizeInlineFilename(parentFile: string, f: string): string {
|
||||
|
||||
/**
|
||||
* Crude implementation of the which(1) shell command.
|
||||
*
|
||||
*
|
||||
* Tries to locate the location of an executable based on the
|
||||
* "PATH" environment variable.
|
||||
*/
|
||||
|
@ -56,7 +56,10 @@ export namespace TalerProtocolTimestamp {
|
||||
t_s: s,
|
||||
};
|
||||
}
|
||||
export function min(t1: TalerProtocolTimestamp, t2: TalerProtocolTimestamp): TalerProtocolTimestamp {
|
||||
export function min(
|
||||
t1: TalerProtocolTimestamp,
|
||||
t2: TalerProtocolTimestamp,
|
||||
): TalerProtocolTimestamp {
|
||||
if (t1.t_s === "never") {
|
||||
return { t_s: t2.t_s };
|
||||
}
|
||||
@ -65,7 +68,6 @@ export namespace TalerProtocolTimestamp {
|
||||
}
|
||||
return { t_s: Math.min(t1.t_s, t2.t_s) };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export interface Duration {
|
||||
|
Loading…
Reference in New Issue
Block a user