From 32e29fd8308514a2ffef3c09efd03b380b116b1c Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Fri, 1 Feb 2019 20:35:30 +0100 Subject: [PATCH] [create-xpub] Add types --- types/create-xpub/create-xpub-tests.ts | 23 ++++++++++++ types/create-xpub/index.d.ts | 52 ++++++++++++++++++++++++++ types/create-xpub/tsconfig.json | 23 ++++++++++++ types/create-xpub/tslint.json | 1 + 4 files changed, 99 insertions(+) create mode 100644 types/create-xpub/create-xpub-tests.ts create mode 100644 types/create-xpub/index.d.ts create mode 100644 types/create-xpub/tsconfig.json create mode 100644 types/create-xpub/tslint.json diff --git a/types/create-xpub/create-xpub-tests.ts b/types/create-xpub/create-xpub-tests.ts new file mode 100644 index 0000000000..c202d819d8 --- /dev/null +++ b/types/create-xpub/create-xpub-tests.ts @@ -0,0 +1,23 @@ +import createXpub = require('create-xpub'); + +// $ExpectType string +createXpub({ + depth: 3, + childNumber: 2147483648, + chainCode: '84cf7d9029cdd9fcadbb3717fd92ec0db7d7d9787c57c13c08fc887c389b566b', + publicKey: + '048bcdcf59f046b13f1eb35b608d1211265fde8cc44fc7a5a7f7107c5cf238095328a0e0d7be17c7d3e48490e8c6433af6d2c3dacc687f3fecaa98a3d05f17de97', +}); + +// $ExpectType string +createXpub({ + networkVersion: createXpub.testnet, + depth: 3, + childNumber: 2147483648, + chainCode: '84cf7d9029cdd9fcadbb3717fd92ec0db7d7d9787c57c13c08fc887c389b566b', + publicKey: + '048bcdcf59f046b13f1eb35b608d1211265fde8cc44fc7a5a7f7107c5cf238095328a0e0d7be17c7d3e48490e8c6433af6d2c3dacc687f3fecaa98a3d05f17de97', +}); + +createXpub.mainnet; // $ExpectType 76067358 +createXpub.testnet; // $ExpectType 70617039 diff --git a/types/create-xpub/index.d.ts b/types/create-xpub/index.d.ts new file mode 100644 index 0000000000..13057396eb --- /dev/null +++ b/types/create-xpub/index.d.ts @@ -0,0 +1,52 @@ +// Type definitions for create-xpub 2.1 +// Project: https://github.com/lukechilds/create-xpub#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = createXpub; + +/** + * Creates a Base58 encoded extended public key (xpub) for use in a + * [BIP32 hierarchical deterministic wallet](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki). + * + * Tip: If you're working with ledgerjs you can pass the output of + * [`getWalletPublicKey()`](http://ledgerhq.github.io/ledgerjs/docs/#btcgetwalletpublickey) almost directly in. + * + * @returns A Base58 encoded extended public key. + */ +declare function createXpub(options: createXpub.Options): string; + +declare namespace createXpub { + /** + * Mainnet (xpub) version bytes. + */ + const mainnet: 0x0488B21E; + /** + * Testnet (tpub) version bytes. + */ + const testnet: 0x043587CF; + + interface Options { + /** + * Network version bytes. + * @default 0x0488B21E + */ + networkVersion?: number; + /** + * The depth of the derived key. + */ + depth: number; + /** + * The child number. + */ + childNumber: number; + /** + * The chain code. + */ + chainCode: string; + /** + * The public key in compressed or uncompressed form. + */ + publicKey: string; + } +} diff --git a/types/create-xpub/tsconfig.json b/types/create-xpub/tsconfig.json new file mode 100644 index 0000000000..53e9b64c11 --- /dev/null +++ b/types/create-xpub/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "create-xpub-tests.ts" + ] +} diff --git a/types/create-xpub/tslint.json b/types/create-xpub/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/create-xpub/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }