Socket
Socket
Sign inDemoInstall

bip174

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bip174 - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

src/lib/converter/input/tapKeySig.d.ts

5

package.json
{
"name": "bip174",
"version": "2.0.1",
"version": "2.1.0",
"description": "",

@@ -25,3 +25,3 @@ "main": "src/lib/psbt.js",

"prettierjs": "prettier 'src/**/*.js' --ignore-path ./.prettierignore",
"test": "npm run format:ci && npm run lint && npm run build && npm run unit",
"test": "npm run format:ci && npm run lint && npm run build && npm run coverage",
"unit": "tape src/tests/*.js src/tests/fromBIP/*.js"

@@ -37,3 +37,2 @@ },

"bitcoinjs-lib": "^5.0.5",
"buffer-json": "^2.0.0",
"nyc": "^14.1.1",

@@ -40,0 +39,0 @@ "prettier": "^1.18.2",

2

src/lib/converter/global/globalXpub.js

@@ -71,3 +71,3 @@ 'use strict';

typeof p === 'string' &&
!!p.match(/^m(\/\d+'?)+$/)
!!p.match(/^m(\/\d+'?)*$/)
);

@@ -74,0 +74,0 @@ }

@@ -10,3 +10,8 @@ /// <reference types="node" />

import * as sighashType from './input/sighashType';
import * as tapKeySig from './input/tapKeySig';
import * as tapLeafScript from './input/tapLeafScript';
import * as tapMerkleRoot from './input/tapMerkleRoot';
import * as tapScriptSig from './input/tapScriptSig';
import * as witnessUtxo from './input/witnessUtxo';
import * as tapTree from './output/tapTree';
declare const globals: {

@@ -47,2 +52,20 @@ unsignedTx: typeof unsignedTx;

checkPubkey: (keyVal: import("../interfaces").KeyValue) => Buffer | undefined;
tapKeySig: typeof tapKeySig;
tapScriptSig: typeof tapScriptSig;
tapLeafScript: typeof tapLeafScript;
tapBip32Derivation: {
decode: (keyVal: import("../interfaces").KeyValue) => import("../interfaces").TapBip32Derivation;
encode: (data: import("../interfaces").TapBip32Derivation) => import("../interfaces").KeyValue;
check: (data: any) => data is import("../interfaces").TapBip32Derivation;
expected: string;
canAddToArray: (array: import("../interfaces").TapBip32Derivation[], item: import("../interfaces").TapBip32Derivation, dupeSet: Set<string>) => boolean;
};
tapInternalKey: {
decode: (keyVal: import("../interfaces").KeyValue) => Buffer;
encode: (data: Buffer) => import("../interfaces").KeyValue;
check: (data: any) => data is Buffer;
expected: string;
canAdd: (currentData: any, newData: any) => boolean;
};
tapMerkleRoot: typeof tapMerkleRoot;
};

@@ -72,3 +95,18 @@ declare const outputs: {

checkPubkey: (keyVal: import("../interfaces").KeyValue) => Buffer | undefined;
tapBip32Derivation: {
decode: (keyVal: import("../interfaces").KeyValue) => import("../interfaces").TapBip32Derivation;
encode: (data: import("../interfaces").TapBip32Derivation) => import("../interfaces").KeyValue;
check: (data: any) => data is import("../interfaces").TapBip32Derivation;
expected: string;
canAddToArray: (array: import("../interfaces").TapBip32Derivation[], item: import("../interfaces").TapBip32Derivation, dupeSet: Set<string>) => boolean;
};
tapTree: typeof tapTree;
tapInternalKey: {
decode: (keyVal: import("../interfaces").KeyValue) => Buffer;
encode: (data: Buffer) => import("../interfaces").KeyValue;
check: (data: any) => data is Buffer;
expected: string;
canAdd: (currentData: any, newData: any) => boolean;
};
};
export { globals, inputs, outputs };

@@ -12,6 +12,13 @@ 'use strict';

const sighashType = require('./input/sighashType');
const tapKeySig = require('./input/tapKeySig');
const tapLeafScript = require('./input/tapLeafScript');
const tapMerkleRoot = require('./input/tapMerkleRoot');
const tapScriptSig = require('./input/tapScriptSig');
const witnessUtxo = require('./input/witnessUtxo');
const tapTree = require('./output/tapTree');
const bip32Derivation = require('./shared/bip32Derivation');
const checkPubkey = require('./shared/checkPubkey');
const redeemScript = require('./shared/redeemScript');
const tapBip32Derivation = require('./shared/tapBip32Derivation');
const tapInternalKey = require('./shared/tapInternalKey');
const witnessScript = require('./shared/witnessScript');

@@ -46,2 +53,12 @@ const globals = {

]),
tapKeySig,
tapScriptSig,
tapLeafScript,
tapBip32Derivation: tapBip32Derivation.makeConverter(
typeFields_1.InputTypes.TAP_BIP32_DERIVATION,
),
tapInternalKey: tapInternalKey.makeConverter(
typeFields_1.InputTypes.TAP_INTERNAL_KEY,
),
tapMerkleRoot,
};

@@ -62,3 +79,10 @@ exports.inputs = inputs;

]),
tapBip32Derivation: tapBip32Derivation.makeConverter(
typeFields_1.OutputTypes.TAP_BIP32_DERIVATION,
),
tapTree,
tapInternalKey: tapInternalKey.makeConverter(
typeFields_1.OutputTypes.TAP_INTERNAL_KEY,
),
};
exports.outputs = outputs;

@@ -0,3 +1,4 @@

/// <reference types="node" />
import { Bip32Derivation, KeyValue } from '../../interfaces';
export declare function makeConverter(TYPE_BYTE: number): {
export declare function makeConverter(TYPE_BYTE: number, isValidPubkey?: (pubkey: Buffer) => boolean): {
decode: (keyVal: KeyValue) => Bip32Derivation;

@@ -4,0 +5,0 @@ encode: (data: Bip32Derivation) => KeyValue;

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const range = n => [...Array(n).keys()];
function makeConverter(TYPE_BYTE) {
const isValidDERKey = pubkey =>
(pubkey.length === 33 && [2, 3].includes(pubkey[0])) ||
(pubkey.length === 65 && 4 === pubkey[0]);
function makeConverter(TYPE_BYTE, isValidPubkey = isValidDERKey) {
function decode(keyVal) {

@@ -12,6 +15,4 @@ if (keyVal.key[0] !== TYPE_BYTE) {

}
if (
!(keyVal.key.length === 34 || keyVal.key.length === 66) ||
![2, 3, 4].includes(keyVal.key[1])
) {
const pubkey = keyVal.key.slice(1);
if (!isValidPubkey(pubkey)) {
throw new Error(

@@ -27,3 +28,2 @@ 'Decode Error: bip32Derivation has invalid pubkey in key 0x' +

}
const pubkey = keyVal.key.slice(1);
const data = {

@@ -68,4 +68,3 @@ masterFingerprint: keyVal.value.slice(0, 4),

typeof data.path === 'string' &&
[33, 65].includes(data.pubkey.length) &&
[2, 3, 4].includes(data.pubkey[0]) &&
isValidPubkey(data.pubkey) &&
data.masterFingerprint.length === 4

@@ -72,0 +71,0 @@ );

@@ -37,2 +37,8 @@ /// <reference types="node" />

porCommitment?: PorCommitment;
tapKeySig?: TapKeySig;
tapScriptSig?: TapScriptSig[];
tapLeafScript?: TapLeafScript[];
tapBip32Derivation?: TapBip32Derivation[];
tapInternalKey?: TapInternalKey;
tapMerkleRoot?: TapMerkleRoot;
}

@@ -49,2 +55,5 @@ export interface PsbtInputExtended extends PsbtInput {

bip32Derivation?: Bip32Derivation[];
tapBip32Derivation?: TapBip32Derivation[];
tapTree?: TapTree;
tapInternalKey?: TapInternalKey;
}

@@ -79,2 +88,25 @@ export interface PsbtOutputExtended extends PsbtOutput {

export declare type PorCommitment = string;
export declare type TapKeySig = Buffer;
export interface TapScriptSig extends PartialSig {
leafHash: Buffer;
}
interface TapScript {
leafVersion: number;
script: Buffer;
}
export declare type ControlBlock = Buffer;
export interface TapLeafScript extends TapScript {
controlBlock: ControlBlock;
}
export interface TapBip32Derivation extends Bip32Derivation {
leafHashes: Buffer[];
}
export declare type TapInternalKey = Buffer;
export declare type TapMerkleRoot = Buffer;
export interface TapLeaf extends TapScript {
depth: number;
}
export interface TapTree {
leaves: TapLeaf[];
}
export declare type TransactionIOCountGetter = (txBuffer: Buffer) => {

@@ -97,1 +129,2 @@ inputCount: number;

export declare type TransactionLocktimeSetter = (locktime: number, txBuffer: Buffer) => Buffer;
export {};

@@ -276,2 +276,46 @@ 'use strict';

break;
case typeFields_1.InputTypes.TAP_KEY_SIG:
checkKeyBuffer(
'input',
keyVal.key,
typeFields_1.InputTypes.TAP_KEY_SIG,
);
input.tapKeySig = convert.inputs.tapKeySig.decode(keyVal);
break;
case typeFields_1.InputTypes.TAP_SCRIPT_SIG:
if (input.tapScriptSig === undefined) {
input.tapScriptSig = [];
}
input.tapScriptSig.push(convert.inputs.tapScriptSig.decode(keyVal));
break;
case typeFields_1.InputTypes.TAP_LEAF_SCRIPT:
if (input.tapLeafScript === undefined) {
input.tapLeafScript = [];
}
input.tapLeafScript.push(convert.inputs.tapLeafScript.decode(keyVal));
break;
case typeFields_1.InputTypes.TAP_BIP32_DERIVATION:
if (input.tapBip32Derivation === undefined) {
input.tapBip32Derivation = [];
}
input.tapBip32Derivation.push(
convert.inputs.tapBip32Derivation.decode(keyVal),
);
break;
case typeFields_1.InputTypes.TAP_INTERNAL_KEY:
checkKeyBuffer(
'input',
keyVal.key,
typeFields_1.InputTypes.TAP_INTERNAL_KEY,
);
input.tapInternalKey = convert.inputs.tapInternalKey.decode(keyVal);
break;
case typeFields_1.InputTypes.TAP_MERKLE_ROOT:
checkKeyBuffer(
'input',
keyVal.key,
typeFields_1.InputTypes.TAP_MERKLE_ROOT,
);
input.tapMerkleRoot = convert.inputs.tapMerkleRoot.decode(keyVal);
break;
default:

@@ -320,2 +364,26 @@ // This will allow inclusion during serialization.

break;
case typeFields_1.OutputTypes.TAP_INTERNAL_KEY:
checkKeyBuffer(
'output',
keyVal.key,
typeFields_1.OutputTypes.TAP_INTERNAL_KEY,
);
output.tapInternalKey = convert.outputs.tapInternalKey.decode(keyVal);
break;
case typeFields_1.OutputTypes.TAP_TREE:
checkKeyBuffer(
'output',
keyVal.key,
typeFields_1.OutputTypes.TAP_TREE,
);
output.tapTree = convert.outputs.tapTree.decode(keyVal);
break;
case typeFields_1.OutputTypes.TAP_BIP32_DERIVATION:
if (output.tapBip32Derivation === undefined) {
output.tapBip32Derivation = [];
}
output.tapBip32Derivation.push(
convert.outputs.tapBip32Derivation.decode(keyVal),
);
break;
default:

@@ -322,0 +390,0 @@ if (!output.unknownKeyVals) output.unknownKeyVals = [];

@@ -16,3 +16,9 @@ export declare enum GlobalTypes {

FINAL_SCRIPTWITNESS = 8,
POR_COMMITMENT = 9
POR_COMMITMENT = 9,
TAP_KEY_SIG = 19,
TAP_SCRIPT_SIG = 20,
TAP_LEAF_SCRIPT = 21,
TAP_BIP32_DERIVATION = 22,
TAP_INTERNAL_KEY = 23,
TAP_MERKLE_ROOT = 24
}

@@ -23,4 +29,7 @@ export declare const INPUT_TYPE_NAMES: string[];

WITNESS_SCRIPT = 1,
BIP32_DERIVATION = 2
BIP32_DERIVATION = 2,
TAP_INTERNAL_KEY = 5,
TAP_TREE = 6,
TAP_BIP32_DERIVATION = 7
}
export declare const OUTPUT_TYPE_NAMES: string[];

@@ -21,2 +21,9 @@ 'use strict';

InputTypes[(InputTypes['POR_COMMITMENT'] = 9)] = 'POR_COMMITMENT';
InputTypes[(InputTypes['TAP_KEY_SIG'] = 19)] = 'TAP_KEY_SIG';
InputTypes[(InputTypes['TAP_SCRIPT_SIG'] = 20)] = 'TAP_SCRIPT_SIG';
InputTypes[(InputTypes['TAP_LEAF_SCRIPT'] = 21)] = 'TAP_LEAF_SCRIPT';
InputTypes[(InputTypes['TAP_BIP32_DERIVATION'] = 22)] =
'TAP_BIP32_DERIVATION';
InputTypes[(InputTypes['TAP_INTERNAL_KEY'] = 23)] = 'TAP_INTERNAL_KEY';
InputTypes[(InputTypes['TAP_MERKLE_ROOT'] = 24)] = 'TAP_MERKLE_ROOT';
})((InputTypes = exports.InputTypes || (exports.InputTypes = {})));

@@ -34,2 +41,8 @@ exports.INPUT_TYPE_NAMES = [

'porCommitment',
'tapKeySig',
'tapScriptSig',
'tapLeafScript',
'tapBip32Derivation',
'tapInternalKey',
'tapMerkleRoot',
];

@@ -41,2 +54,6 @@ var OutputTypes;

OutputTypes[(OutputTypes['BIP32_DERIVATION'] = 2)] = 'BIP32_DERIVATION';
OutputTypes[(OutputTypes['TAP_INTERNAL_KEY'] = 5)] = 'TAP_INTERNAL_KEY';
OutputTypes[(OutputTypes['TAP_TREE'] = 6)] = 'TAP_TREE';
OutputTypes[(OutputTypes['TAP_BIP32_DERIVATION'] = 7)] =
'TAP_BIP32_DERIVATION';
})((OutputTypes = exports.OutputTypes || (exports.OutputTypes = {})));

@@ -47,2 +64,5 @@ exports.OUTPUT_TYPE_NAMES = [

'bip32Derivation',
'tapInternalKey',
'tapTree',
'tapBip32Derivation',
];

@@ -119,3 +119,3 @@ 'use strict';

const index = outputs.length - 1;
const output = checkForInput(outputs, index);
const output = checkForOutput(outputs, index);
exports.updateOutput(data, output);

@@ -122,0 +122,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc