Skip to content

Commit

Permalink
Merge branch 'runcase'
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonandjay committed Mar 14, 2024
2 parents c2f32d6 + 1ea51f0 commit 9cbe702
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 9 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"tiny-secp256k1": "^2.2.0",
"ts-node": "^8.3.0",
"typedoc": "^0.25.1",
"typedoc-plugin-bitcoinjs-runcase": "^1.0.2",
"typescript": "^4.4.4"
},
"license": "MIT"
Expand Down
26 changes: 25 additions & 1 deletion src/address.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
* @packageDocumentation
*/
import { Network } from './networks';
/** base58check decode result */
/**
* base58check decode result
*/
export interface Base58CheckResult {
/** address hash */
hash: Buffer;
Expand All @@ -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;
/**
Expand Down
22 changes: 22 additions & 0 deletions src/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand Down
26 changes: 25 additions & 1 deletion ts_src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Check failure on line 78 in ts_src/address.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
*

Check failure on line 79 in ts_src/address.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* const decode = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH')
*

Check failure on line 81 in ts_src/address.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* console.log(decode.version) // 0
*

Check failure on line 83 in ts_src/address.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* console.log(decode.hash.toString('hex')) // 751e76e8199196d454941c45d1b3a323f1433bd6
* ```
*/
export function fromBase58Check(address: string): Base58CheckResult {
const payload = Buffer.from(bs58check.decode(address));
Expand All @@ -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

Check failure on line 104 in ts_src/address.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
*

Check failure on line 105 in ts_src/address.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* const actual = address.fromBech32('tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy')
*

Check failure on line 107 in ts_src/address.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* console.log(actual.version) // 0
*

Check failure on line 109 in ts_src/address.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* console.log(actual.prefix) // tb
*

Check failure on line 111 in ts_src/address.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* console.log(actual.data.toString('hex')) // 000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433
* ```
*/
export function fromBech32(address: string): Bech32Result {
let result;
Expand Down
1 change: 1 addition & 0 deletions typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"searchGroupBoosts": {
"Classes": 1.5
},
"plugin": ["typedoc-plugin-bitcoinjs-runcase"],
"visibilityFilters": {},
"hideGenerator": true,
"excludePrivate": true,
Expand Down

0 comments on commit 9cbe702

Please sign in to comment.