mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-12 18:51:21 +01:00
REF: ts convert multisig-cosigner
This commit is contained in:
parent
1c2f1ad3f9
commit
29e1d5a641
2 changed files with 18 additions and 13 deletions
|
@ -3,15 +3,19 @@ import b58 from 'bs58check';
|
||||||
|
|
||||||
import ecc from '../blue_modules/noble_ecc';
|
import ecc from '../blue_modules/noble_ecc';
|
||||||
import { MultisigHDWallet } from './wallets/multisig-hd-wallet';
|
import { MultisigHDWallet } from './wallets/multisig-hd-wallet';
|
||||||
|
import assert from 'assert';
|
||||||
const bip32 = BIP32Factory(ecc);
|
const bip32 = BIP32Factory(ecc);
|
||||||
|
|
||||||
export class MultisigCosigner {
|
export class MultisigCosigner {
|
||||||
constructor(data) {
|
private _data: string;
|
||||||
|
private _fp: string = '';
|
||||||
|
private _xpub: string = '';
|
||||||
|
private _path: string = '';
|
||||||
|
private _valid: boolean = false;
|
||||||
|
private _cosigners: any[];
|
||||||
|
|
||||||
|
constructor(data: string) {
|
||||||
this._data = data;
|
this._data = data;
|
||||||
this._fp = false;
|
|
||||||
this._xpub = false;
|
|
||||||
this._path = false;
|
|
||||||
this._valid = false;
|
|
||||||
this._cosigners = [];
|
this._cosigners = [];
|
||||||
|
|
||||||
// is it plain simple Zpub/Ypub/xpub?
|
// is it plain simple Zpub/Ypub/xpub?
|
||||||
|
@ -70,6 +74,7 @@ export class MultisigCosigner {
|
||||||
|
|
||||||
// a bit more logic here: according to the formal BIP48 spec, this xpub field _can_ start with 'xpub', but
|
// a bit more logic here: according to the formal BIP48 spec, this xpub field _can_ start with 'xpub', but
|
||||||
// the actual type of segwit can be inferred from the path
|
// the actual type of segwit can be inferred from the path
|
||||||
|
assert(this._xpub);
|
||||||
if (
|
if (
|
||||||
this._xpub.startsWith('xpub') &&
|
this._xpub.startsWith('xpub') &&
|
||||||
[MultisigHDWallet.PATH_NATIVE_SEGWIT, MultisigHDWallet.PATH_WRAPPED_SEGWIT].includes(this._path)
|
[MultisigHDWallet.PATH_NATIVE_SEGWIT, MultisigHDWallet.PATH_WRAPPED_SEGWIT].includes(this._path)
|
||||||
|
@ -126,7 +131,7 @@ export class MultisigCosigner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static isXpubValid(key) {
|
static isXpubValid(key: string) {
|
||||||
let xpub;
|
let xpub;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -139,7 +144,7 @@ export class MultisigCosigner {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static exportToJson(xfp, xpub, path) {
|
static exportToJson(xfp: string, xpub: string, path: string) {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
xfp,
|
xfp,
|
||||||
xpub,
|
xpub,
|
|
@ -2158,9 +2158,9 @@ describe('multisig-cosigner', () => {
|
||||||
it('cant parse bs', () => {
|
it('cant parse bs', () => {
|
||||||
const cosigner = new MultisigCosigner('asdfasdgsqwrgqwegq');
|
const cosigner = new MultisigCosigner('asdfasdgsqwrgqwegq');
|
||||||
assert.ok(!cosigner.isValid());
|
assert.ok(!cosigner.isValid());
|
||||||
assert.strictEqual(cosigner.getFp(), false);
|
assert.strictEqual(cosigner.getFp(), '');
|
||||||
assert.strictEqual(cosigner.getXpub(), false);
|
assert.strictEqual(cosigner.getXpub(), '');
|
||||||
assert.strictEqual(cosigner.getPath(), false);
|
assert.strictEqual(cosigner.getPath(), '');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can parse file from coldcard with multiple xpubs (for different formats)', () => {
|
it('can parse file from coldcard with multiple xpubs (for different formats)', () => {
|
||||||
|
@ -2178,9 +2178,9 @@ describe('multisig-cosigner', () => {
|
||||||
const cosigner = new MultisigCosigner(cc);
|
const cosigner = new MultisigCosigner(cc);
|
||||||
assert.strictEqual(cosigner.howManyCosignersWeHave(), 3);
|
assert.strictEqual(cosigner.howManyCosignersWeHave(), 3);
|
||||||
assert.ok(cosigner.isValid());
|
assert.ok(cosigner.isValid());
|
||||||
assert.strictEqual(cosigner.getFp(), false);
|
assert.strictEqual(cosigner.getFp(), '');
|
||||||
assert.strictEqual(cosigner.getXpub(), false);
|
assert.strictEqual(cosigner.getXpub(), '');
|
||||||
assert.strictEqual(cosigner.getPath(), false);
|
assert.strictEqual(cosigner.getPath(), '');
|
||||||
|
|
||||||
const [c1, c2, c3] = cosigner.getAllCosigners();
|
const [c1, c2, c3] = cosigner.getAllCosigners();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue