Skip to content

Commit

Permalink
Merge pull request #2072 from jasonandjay/reduant
Browse files Browse the repository at this point in the history
Remove methods that neither used nor export
  • Loading branch information
junderw authored Apr 8, 2024
2 parents da6e2fb + 562f123 commit 2ae74ca
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ test/*.js
test/integration/*.js
!test/ts-node-register.js
docs
plugin
8 changes: 0 additions & 8 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ export declare function stacksEqual(a: Buffer[], b: Buffer[]): boolean;
* @returns True if the value is a valid elliptic curve point, false otherwise.
*/
export declare function isPoint(p: Buffer | number | undefined | null): boolean;
export declare function UInt31(value: number): boolean;
export declare function BIP32Path(value: string): boolean;
export declare namespace BIP32Path {
var toJSON: () => string;
}
export declare function Signer(obj: any): boolean;
export declare function Satoshi(value: number): boolean;
export declare const ECPoint: any;
export declare const Network: any;
export interface XOnlyPointAddTweakResult {
parity: 1 | 0;
xOnlyPubkey: Uint8Array;
Expand Down
43 changes: 0 additions & 43 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ exports.oneOf =
exports.isTaptree =
exports.isTapleaf =
exports.TAPLEAF_VERSION_MASK =
exports.Network =
exports.ECPoint =
exports.Satoshi =
exports.Signer =
exports.BIP32Path =
exports.UInt31 =
exports.isPoint =
exports.stacksEqual =
exports.typeforce =
Expand Down Expand Up @@ -72,49 +67,11 @@ function isPoint(p) {
return false;
}
exports.isPoint = isPoint;
const UINT31_MAX = Math.pow(2, 31) - 1;
function UInt31(value) {
return exports.typeforce.UInt32(value) && value <= UINT31_MAX;
}
exports.UInt31 = UInt31;
function BIP32Path(value) {
return (
exports.typeforce.String(value) && !!value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
);
}
exports.BIP32Path = BIP32Path;
BIP32Path.toJSON = () => {
return 'BIP32 derivation path';
};
function Signer(obj) {
return (
(exports.typeforce.Buffer(obj.publicKey) ||
typeof obj.getPublicKey === 'function') &&
typeof obj.sign === 'function'
);
}
exports.Signer = Signer;
const SATOSHI_MAX = 21 * 1e14;
function Satoshi(value) {
return exports.typeforce.UInt53(value) && value <= SATOSHI_MAX;
}
exports.Satoshi = Satoshi;
// external dependent types
exports.ECPoint = exports.typeforce.quacksLike('Point');
// exposed, external API
exports.Network = exports.typeforce.compile({
messagePrefix: exports.typeforce.oneOf(
exports.typeforce.Buffer,
exports.typeforce.String,
),
bip32: {
public: exports.typeforce.UInt32,
private: exports.typeforce.UInt32,
},
pubKeyHash: exports.typeforce.UInt8,
scriptHash: exports.typeforce.UInt8,
wif: exports.typeforce.UInt8,
});
exports.TAPLEAF_VERSION_MASK = 0xfe;
function isTapleaf(o) {
if (!o || !('output' in o)) return false;
Expand Down
37 changes: 0 additions & 37 deletions test/types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,4 @@ describe('types', () => {
});
});
});

describe('UInt31', () => {
const UINT31_MAX = Math.pow(2, 31) - 1;
it('return true for valid values', () => {
assert.strictEqual(types.UInt31(0), true);
assert.strictEqual(types.UInt31(1000), true);
assert.strictEqual(types.UInt31(UINT31_MAX), true);
});

it('return false for negative values', () => {
assert.strictEqual(types.UInt31(-1), false);
assert.strictEqual(types.UInt31(-UINT31_MAX), false);
});

it(`return false for value > ${UINT31_MAX}`, () => {
assert.strictEqual(types.UInt31(UINT31_MAX + 1), false);
});
});

describe('BIP32Path', () => {
it('return true for valid paths', () => {
assert.strictEqual(types.BIP32Path("m/0'/0'"), true);
assert.strictEqual(types.BIP32Path("m/0'/0"), true);
assert.strictEqual(types.BIP32Path("m/0'/1'/2'/3/4'"), true);
});

it('return false for invalid paths', () => {
assert.strictEqual(types.BIP32Path('m'), false);
assert.strictEqual(types.BIP32Path("n/0'/0'"), false);
assert.strictEqual(types.BIP32Path("m/0'/x"), false);
});

it('return "BIP32 derivation path" for JSON.strigify()', () => {
const toJsonValue = JSON.stringify(types.BIP32Path);
assert.equal(toJsonValue, '"BIP32 derivation path"');
});
});
});
35 changes: 0 additions & 35 deletions ts_src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,11 @@ export function isPoint(p: Buffer | number | undefined | null): boolean {
return false;
}

const UINT31_MAX: number = Math.pow(2, 31) - 1;
export function UInt31(value: number): boolean {
return typeforce.UInt32(value) && value <= UINT31_MAX;
}

export function BIP32Path(value: string): boolean {
return typeforce.String(value) && !!value.match(/^(m\/)?(\d+'?\/)*\d+'?$/);
}
BIP32Path.toJSON = (): string => {
return 'BIP32 derivation path';
};

export function Signer(obj: any): boolean {
return (
(typeforce.Buffer(obj.publicKey) ||
typeof obj.getPublicKey === 'function') &&
typeof obj.sign === 'function'
);
}

const SATOSHI_MAX: number = 21 * 1e14;
export function Satoshi(value: number): boolean {
return typeforce.UInt53(value) && value <= SATOSHI_MAX;
}

// external dependent types
export const ECPoint = typeforce.quacksLike('Point');

// exposed, external API
export const Network = typeforce.compile({
messagePrefix: typeforce.oneOf(typeforce.Buffer, typeforce.String),
bip32: {
public: typeforce.UInt32,
private: typeforce.UInt32,
},
pubKeyHash: typeforce.UInt8,
scriptHash: typeforce.UInt8,
wif: typeforce.UInt8,
});

export interface XOnlyPointAddTweakResult {
parity: 1 | 0;
xOnlyPubkey: Uint8Array;
Expand Down

0 comments on commit 2ae74ca

Please sign in to comment.