From 65b54916fd86b667a5e1d0295d8982aa3a1b7277 Mon Sep 17 00:00:00 2001 From: jasonandjay <342690199@qq.com> Date: Mon, 11 Mar 2024 23:38:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8feature:=20add=20typedoc-plugin=20?= =?UTF-8?q?to=20runcase=20in=20the=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + typedoc.json | 1 + 2 files changed, 2 insertions(+) diff --git a/package.json b/package.json index 13c845713..997318f1e 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "tiny-secp256k1": "^2.2.0", "ts-node": "^8.3.0", "typedoc": "^0.25.1", + "typedoc-plugin-bitcoinjs-runcase": "^1.0.1", "typescript": "^4.4.4" }, "license": "MIT" diff --git a/typedoc.json b/typedoc.json index 041e85042..c731be6c8 100644 --- a/typedoc.json +++ b/typedoc.json @@ -10,6 +10,7 @@ "searchGroupBoosts": { "Classes": 1.5 }, + "plugin": ["typedoc-plugin-bitcoinjs-runcase"], "visibilityFilters": {}, "hideGenerator": true, "excludePrivate": true, From 1ea51f0035e3d1de2f0f1c96962436ec7ae20fee Mon Sep 17 00:00:00 2001 From: jasonandjay <342690199@qq.com> Date: Thu, 14 Mar 2024 14:56:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=84=20docs:=20=20integrate=20runca?= =?UTF-8?q?se=20into=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 14 +++++++------- package.json | 2 +- src/address.d.ts | 26 +++++++++++++++++++++++++- src/address.js | 22 ++++++++++++++++++++++ ts_src/address.ts | 26 +++++++++++++++++++++++++- 5 files changed, 80 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index c02f958ed..70bc76251 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,7 @@ "tiny-secp256k1": "^2.2.0", "ts-node": "^8.3.0", "typedoc": "^0.25.1", - "typedoc-plugin-bitcoinjs-runcase": "^1.0.1", + "typedoc-plugin-bitcoinjs-runcase": "^1.0.2", "typescript": "^4.4.4" }, "engines": { @@ -4355,9 +4355,9 @@ } }, "node_modules/typedoc-plugin-bitcoinjs-runcase": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/typedoc-plugin-bitcoinjs-runcase/-/typedoc-plugin-bitcoinjs-runcase-1.0.1.tgz", - "integrity": "sha512-tqbnCCP2ku2egGjwn0G0bRNeSH/lh3FT7khrpyYdx1kDu8rjKlyqJX7yPgEj4biBHJATJnQGxp3cKmYG0wv5uw==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/typedoc-plugin-bitcoinjs-runcase/-/typedoc-plugin-bitcoinjs-runcase-1.0.2.tgz", + "integrity": "sha512-Aa9E6aBXA1CKHIos2NJXWTbn38J6ZBV2saTeWyja489mlUBY6O1gyBIiziDl4R7rS/Vu/9AaRAnWGay42h8bBw==", "dev": true, "dependencies": { "react": "^18.2.0", @@ -7893,9 +7893,9 @@ } }, "typedoc-plugin-bitcoinjs-runcase": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/typedoc-plugin-bitcoinjs-runcase/-/typedoc-plugin-bitcoinjs-runcase-1.0.1.tgz", - "integrity": "sha512-tqbnCCP2ku2egGjwn0G0bRNeSH/lh3FT7khrpyYdx1kDu8rjKlyqJX7yPgEj4biBHJATJnQGxp3cKmYG0wv5uw==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/typedoc-plugin-bitcoinjs-runcase/-/typedoc-plugin-bitcoinjs-runcase-1.0.2.tgz", + "integrity": "sha512-Aa9E6aBXA1CKHIos2NJXWTbn38J6ZBV2saTeWyja489mlUBY6O1gyBIiziDl4R7rS/Vu/9AaRAnWGay42h8bBw==", "dev": true, "requires": { "react": "^18.2.0", diff --git a/package.json b/package.json index 997318f1e..fe434cc40 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "tiny-secp256k1": "^2.2.0", "ts-node": "^8.3.0", "typedoc": "^0.25.1", - "typedoc-plugin-bitcoinjs-runcase": "^1.0.1", + "typedoc-plugin-bitcoinjs-runcase": "^1.0.2", "typescript": "^4.4.4" }, "license": "MIT" diff --git a/src/address.d.ts b/src/address.d.ts index 6b5bc9c2a..4034be625 100644 --- a/src/address.d.ts +++ b/src/address.d.ts @@ -9,7 +9,9 @@ * @packageDocumentation */ import { Network } from './networks'; -/** base58check decode result */ +/** + * base58check decode result + */ export interface Base58CheckResult { /** address hash */ hash: Buffer; @@ -27,10 +29,32 @@ export interface Bech32Result { } /** * decode address with base58 specification, return address version and address hash if valid + * * @case + * ```ts + * // You can test it here and find more case in test/address.spec.ts + * + * const decode = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH') + * + * console.log(decode.version) // 0 + * + * console.log(decode.hash.toString('hex')) // 751e76e8199196d454941c45d1b3a323f1433bd6 + * ``` */ export declare function fromBase58Check(address: string): Base58CheckResult; /** * decode address with bech32 specification, return address version、address prefix and address data if valid + * * @case + * ```ts + * // You can test it here and find more case in test/address.spec.ts + * + * const actual = address.fromBech32('tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy') + * + * console.log(actual.version) // 0 + * + * console.log(actual.prefix) // tb + * + * console.log(actual.data.toString('hex')) // 000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433 + * ``` */ export declare function fromBech32(address: string): Bech32Result; /** diff --git a/src/address.js b/src/address.js index ad3ceeb1a..8719108f1 100644 --- a/src/address.js +++ b/src/address.js @@ -43,6 +43,16 @@ function _toFutureSegwitAddress(output, network) { } /** * decode address with base58 specification, return address version and address hash if valid + * * @case + * ```ts + * // You can test it here and find more case in test/address.spec.ts + * + * const decode = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH') + * + * console.log(decode.version) // 0 + * + * console.log(decode.hash.toString('hex')) // 751e76e8199196d454941c45d1b3a323f1433bd6 + * ``` */ function fromBase58Check(address) { const payload = Buffer.from(bs58check.decode(address)); @@ -56,6 +66,18 @@ function fromBase58Check(address) { exports.fromBase58Check = fromBase58Check; /** * decode address with bech32 specification, return address version、address prefix and address data if valid + * * @case + * ```ts + * // You can test it here and find more case in test/address.spec.ts + * + * const actual = address.fromBech32('tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy') + * + * console.log(actual.version) // 0 + * + * console.log(actual.prefix) // tb + * + * console.log(actual.data.toString('hex')) // 000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433 + * ``` */ function fromBech32(address) { let result; diff --git a/ts_src/address.ts b/ts_src/address.ts index cbd03da1f..6d9754d36 100644 --- a/ts_src/address.ts +++ b/ts_src/address.ts @@ -15,7 +15,9 @@ import { typeforce, tuple, Hash160bit, UInt8 } from './types'; import { bech32, bech32m } from 'bech32'; import * as bs58check from 'bs58check'; -/** base58check decode result */ +/** + * base58check decode result + */ export interface Base58CheckResult { /** address hash */ hash: Buffer; @@ -71,6 +73,16 @@ function _toFutureSegwitAddress(output: Buffer, network: Network): string { /** * decode address with base58 specification, return address version and address hash if valid + * * @case + * ```ts + * // You can test it here and find more case in test/address.spec.ts + * + * const decode = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH') + * + * console.log(decode.version) // 0 + * + * console.log(decode.hash.toString('hex')) // 751e76e8199196d454941c45d1b3a323f1433bd6 + * ``` */ export function fromBase58Check(address: string): Base58CheckResult { const payload = Buffer.from(bs58check.decode(address)); @@ -87,6 +99,18 @@ export function fromBase58Check(address: string): Base58CheckResult { /** * decode address with bech32 specification, return address version、address prefix and address data if valid + * * @case + * ```ts + * // You can test it here and find more case in test/address.spec.ts + * + * const actual = address.fromBech32('tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy') + * + * console.log(actual.version) // 0 + * + * console.log(actual.prefix) // tb + * + * console.log(actual.data.toString('hex')) // 000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433 + * ``` */ export function fromBech32(address: string): Bech32Result { let result;