Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@samouraiwallet/bip47

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@samouraiwallet/bip47 - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

9

CHANGELOG.md
# Changelog
## v0.8.0
### Breaking
- minimum required Node.js version is now v16.6.0
- API now uses `Uint8Array` instead of `Buffer`
### Chores
- updated dependencies
- switched from `create-hash` to `@noble/hashes`
## v0.7.0

@@ -4,0 +13,0 @@ ### Features

40

dist/payment-code.d.ts
import { BIP32Interface } from 'bip32';
import { Network, TinySecp256k1Interface, AddressType } from './types';
export declare const BIP47Factory: (ecc: TinySecp256k1Interface) => {
fromSeed: (bSeed: Buffer, id: number | string, network?: Network) => {
version: Buffer;
buf: Buffer;
fromSeed: (bSeed: Uint8Array, id: number | string, network?: Network) => {
version: Uint8Array;
buf: Uint8Array;
network: Network;
root: BIP32Interface;
readonly features: Buffer;
readonly pubKey: Buffer;
readonly chainCode: Buffer;
readonly paymentCode: Buffer;
readonly features: Uint8Array;
readonly pubKey: Uint8Array;
readonly chainCode: Uint8Array;
readonly paymentCode: Uint8Array;
toBase58(): string;

@@ -24,10 +24,10 @@ _hasPrivKeys(): boolean;

fromBase58: (inString: string, network?: Network) => {
version: Buffer;
buf: Buffer;
version: Uint8Array;
buf: Uint8Array;
network: Network;
root: BIP32Interface;
readonly features: Buffer;
readonly pubKey: Buffer;
readonly chainCode: Buffer;
readonly paymentCode: Buffer;
readonly features: Uint8Array;
readonly pubKey: Uint8Array;
readonly chainCode: Uint8Array;
readonly paymentCode: Uint8Array;
toBase58(): string;

@@ -43,11 +43,11 @@ _hasPrivKeys(): boolean;

};
fromBuffer: (buf: Buffer, network?: Network) => {
version: Buffer;
buf: Buffer;
fromBuffer: (buf: Uint8Array, network?: Network) => {
version: Uint8Array;
buf: Uint8Array;
network: Network;
root: BIP32Interface;
readonly features: Buffer;
readonly pubKey: Buffer;
readonly chainCode: Buffer;
readonly paymentCode: Buffer;
readonly features: Uint8Array;
readonly pubKey: Uint8Array;
readonly chainCode: Uint8Array;
readonly paymentCode: Uint8Array;
toBase58(): string;

@@ -54,0 +54,0 @@ _hasPrivKeys(): boolean;

@@ -17,3 +17,3 @@ import { BIP32Factory } from 'bip32';

this.network = network;
this.root = bip32.fromPublicKey(this.pubKey, this.chainCode, this.network);
this.root = bip32.fromPublicKey(Buffer.from(this.pubKey), Buffer.from(this.chainCode), this.network);
}

@@ -132,12 +132,13 @@ get features() {

const fromSeed = (bSeed, id, network = utils.networks.bitcoin) => {
const reserved = Buffer.alloc(13, 0);
const root = bip32.fromSeed(bSeed);
const root = bip32.fromSeed(Buffer.from(bSeed));
const coinType = (network.pubKeyHash === utils.networks.bitcoin.pubKeyHash) ? '0' : '1';
const root_bip47 = root.derivePath(`m/47'/${coinType}'/${id}'`);
let pc = Buffer.from('0100', 'hex');
pc = Buffer.concat([pc, root_bip47.publicKey]);
pc = Buffer.concat([pc, root_bip47.chainCode]);
if (pc.length !== 67)
throw new TypeError('Missing or wrong publicKey or chainCode');
pc = Buffer.concat([pc, reserved]);
const pc = new Uint8Array(80);
pc.set([1, 0]);
if (root_bip47.publicKey.length !== 33)
throw new TypeError('Missing or wrong publicKey');
pc.set(root_bip47.publicKey, 2);
if (root_bip47.chainCode.length !== 32)
throw new TypeError('Missing or wrong chainCode');
pc.set(root_bip47.chainCode, 35);
const pcode = new PaymentCode(pc, network);

@@ -144,0 +145,0 @@ pcode.root = root_bip47;

import { TinySecp256k1Interface as TinySecp256k1InterfaceBIP32 } from 'bip32';
export declare type AddressType = 'p2pkh' | 'p2sh' | 'p2wpkh';
export type AddressType = 'p2pkh' | 'p2sh' | 'p2wpkh';
interface Bip32 {

@@ -4,0 +4,0 @@ public: number;

/// <reference types="node" />
import { Network } from './types';
export declare const networks: Record<'bitcoin' | 'regtest' | 'testnet', Network>;
export declare function ripemd160(buffer: Buffer): Buffer;
export declare function sha256(buffer: Buffer): Buffer;
export declare function hash160(buffer: Buffer): Buffer;
export declare function toBase58Check(hash: Buffer, version: number): string;
export declare function getP2pkhAddress(pubkey: Buffer, network: Network): string;
export declare function ripemd160(buffer: Uint8Array): Uint8Array;
export declare function sha256(buffer: Uint8Array): Uint8Array;
export declare function hash160(buffer: Uint8Array): Uint8Array;
export declare function toBase58Check(hash: Uint8Array, version: number): string;
export declare function getP2pkhAddress(pubkey: Uint8Array, network: Network): string;
export declare function getP2shAddress(pubkey: Buffer, network: Network): string;
export declare function getP2wpkhAddress(pubkey: Buffer, network: Network): string;
export declare function getP2wpkhAddress(pubkey: Uint8Array, network: Network): string;
//# sourceMappingURL=utils.d.ts.map

@@ -1,2 +0,3 @@

import createHash from 'create-hash';
import { sha256 as noble_sha256 } from '@noble/hashes/sha256';
import { ripemd160 as noble_ripemd160 } from '@noble/hashes/ripemd160';
import bs58check from 'bs58check';

@@ -40,6 +41,6 @@ import { bech32 } from 'bech32';

export function ripemd160(buffer) {
return createHash('rmd160').update(buffer).digest();
return noble_ripemd160(buffer);
}
export function sha256(buffer) {
return createHash('sha256').update(buffer).digest();
return noble_sha256(buffer);
}

@@ -50,5 +51,5 @@ export function hash160(buffer) {

export function toBase58Check(hash, version) {
const payload = Buffer.allocUnsafe(21);
payload.writeUInt8(version, 0);
hash.copy(payload, 1);
const payload = new Uint8Array(21);
payload.set([version], 0);
payload.set(hash, 1);
return bs58check.encode(payload);

@@ -60,4 +61,7 @@ }

export function getP2shAddress(pubkey, network) {
const push20 = Buffer.from(new Uint8Array([0, 0x14]));
const scriptSig = Buffer.concat([push20, hash160(pubkey)]);
const push20 = new Uint8Array([0, 0x14]);
const hash = hash160(pubkey);
const scriptSig = new Uint8Array(push20.length + hash.length);
scriptSig.set(push20);
scriptSig.set(hash, push20.length);
return toBase58Check(hash160(scriptSig), network.scriptHash);

@@ -64,0 +68,0 @@ }

{
"name": "@samouraiwallet/bip47",
"version": "0.7.0",
"version": "0.8.0",
"engines": {
"node": ">=14.0.0"
"node": ">=16.6.0"
},

@@ -23,3 +23,4 @@ "description": "A set of utilities for working with BIP47 and bitcoinjs-lib",

"scripts": {
"test": "mocha",
"test": "vitest run",
"test:watch": "vitest watch",
"typescript": "tsc --noEmit",

@@ -44,6 +45,6 @@ "lint": "eslint --ext .ts src/ test/",

"dependencies": {
"@noble/hashes": "1.3.0",
"bech32": "2.0.0",
"bip32": "3.1.0",
"bs58check": "2.1.2",
"create-hash": "1.2.0"
"bip32": "4.0.0",
"bs58check": "3.0.1"
},

@@ -53,16 +54,15 @@ "devDependencies": {

"@types/create-hash": "^1.2.2",
"@types/mocha": "^10.0.0",
"@types/node": "^16.11.63",
"@types/node": "^16.18.30",
"@types/tiny-secp256k1": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"eslint": "^8.25.0",
"eslint-import-resolver-typescript": "^3.5.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-unicorn": "^44.0.2",
"mocha": "^10.1.0",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"@vitest/coverage-c8": "^0.31.0",
"eslint": "^8.40.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-unicorn": "^47.0.0",
"tiny-secp256k1": "^2.2.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
"typescript": "^5.0.4",
"vitest": "^0.31.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