Skip to content

Commit 5bf4367

Browse files
committed
⏪ rollback: remove runcase of address module
1 parent 4a1913e commit 5bf4367

File tree

1 file changed

+1
-113
lines changed

1 file changed

+1
-113
lines changed

ts_src/address.ts

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* bitcoin address decode and encode tools, include base58、bech32 and output script
33
*
4-
* networks support bitcoin、litecoin、bitcoin testnet、litecoin testnet、bitcoin regtest、litecoin regtest and so on
4+
* networks support bitcoin、bitcoin testnet and bitcoin regtest
55
*
66
* addresses support P2PKH、P2SH、P2WPKH、P2WSH、P2TR and so on
77
*
@@ -71,13 +71,6 @@ function _toFutureSegwitAddress(output: Buffer, network: Network): string {
7171

7272
/**
7373
* decode address with base58 specification, return address version and address hash if valid
74-
* @case
75-
* ```ts
76-
* // You can test it here and find more case in test/address.spec.ts
77-
* const result = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH')
78-
* console.log(JSON.stringify(result))
79-
* // => {"version":0,"hash":{"type":"Buffer","data":[117,30,118,232,25,145,150,212,84,148,28,69,209,179,163,35,241,67,59,214]}}
80-
* ```
8174
*/
8275
export function fromBase58Check(address: string): Base58CheckResult {
8376
const payload = Buffer.from(bs58check.decode(address));
@@ -94,40 +87,6 @@ export function fromBase58Check(address: string): Base58CheckResult {
9487

9588
/**
9689
* decode address with bech32 specification, return address version、address prefix and address data if valid
97-
* @example
98-
* ```ts
99-
* // valid case
100-
* fromBech32('BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4')
101-
* // => {version: 0, prefix: 'bc', data: <Buffer 75 1e 76 e8 19 91 96 d4 54 94 1c 45 d1 b3 a3 23 f1 43 3b d6>}
102-
*
103-
* // invalid case
104-
* fromBase58Check('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5')
105-
* // => Invalid checksum
106-
*
107-
* // invalid case
108-
* fromBase58Check('tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7')
109-
* // => Mixed-case string
110-
*
111-
* // invalid case
112-
* fromBase58Check('tb1pw508d6qejxtdg4y5r3zarquvzkan')
113-
* // => Excess padding
114-
*
115-
* // invalid case
116-
* fromBase58Check('bc1zw508d6qejxtdg4y5r3zarvaryvq37eag7')
117-
* // => Excess padding
118-
*
119-
* // invalid case
120-
* fromBase58Check('bc1zw508d6qejxtdg4y5r3zarvaryvq37eag7')
121-
* // => Non-zero padding
122-
*
123-
* // invalid case
124-
* fromBase58Check('tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv')
125-
* // => uses wrong encoding
126-
*
127-
* // invalid case
128-
* fromBase58Check('bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqh2y7hd')
129-
* // => uses wrong encoding
130-
* ```
13190
*/
13291
export function fromBech32(address: string): Bech32Result {
13392
let result;
@@ -156,13 +115,6 @@ export function fromBech32(address: string): Bech32Result {
156115

157116
/**
158117
* encode address hash to base58 address with version
159-
*
160-
* @example
161-
* ```ts
162-
* // valid case
163-
* toBase58Check('751e76e8199196d454941c45d1b3a323f1433bd6', 0)
164-
* // => 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
165-
* ```
166118
*/
167119
export function toBase58Check(hash: Buffer, version: number): string {
168120
typeforce(tuple(Hash160bit, UInt8), arguments);
@@ -176,13 +128,6 @@ export function toBase58Check(hash: Buffer, version: number): string {
176128

177129
/**
178130
* encode address hash to bech32 address with version and prefix
179-
*
180-
* @example
181-
* ```ts
182-
* // valid case
183-
* toBech32('000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433', 0, 'tb)
184-
* // => tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy
185-
* ```
186131
*/
187132
export function toBech32(
188133
data: Buffer,
@@ -199,45 +144,6 @@ export function toBech32(
199144

200145
/**
201146
* decode address from output script with network, return address if matched
202-
* @example
203-
* ```ts
204-
* // valid case
205-
* fromOutputScript('OP_DUP OP_HASH160 751e76e8199196d454941c45d1b3a323f1433bd6 OP_EQUALVERIFY OP_CHECKSIG', 'bicoin)
206-
* // => 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
207-
*
208-
* // invalid case
209-
* fromOutputScript('031f1e68f82112b373f0fe980b3a89d212d2b5c01fb51eb25acb8b4c4b4299ce95 OP_CHECKSIG', undefined)
210-
* // => has no matching Address
211-
*
212-
* // invalid case
213-
* fromOutputScript('OP_TRUE 032487c2a32f7c8d57d2a93906a6457afd00697925b0e6e145d89af6d3bca33016 02308673d16987eaa010e540901cc6fe3695e758c19f46ce604e174dac315e685a OP_2 OP_CHECKMULTISIG', undefined)
214-
* // => has no matching Address
215-
*
216-
* // invalid case
217-
* fromOutputScript('OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474', undefined)
218-
* // => has no matching Address
219-
*
220-
* // invalid case
221-
* fromOutputScript('OP_0 75', undefined)
222-
* // => has no matching Address
223-
*
224-
* // invalid case
225-
* fromOutputScript('OP_0 751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd675', undefined)
226-
* // => has no matching Address
227-
*
228-
* // invalid case
229-
* fromOutputScript('OP_1 75', undefined)
230-
* // => has no matching Address
231-
*
232-
* // invalid case
233-
* fromOutputScript('OP_1 751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd675', undefined)
234-
* // => has no matching Address
235-
*
236-
* // invalid case
237-
* fromOutputScript('OP_1 fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f', undefined)
238-
* // => has no matching Address
239-
*
240-
* ```
241147
*/
242148
export function fromOutputScript(output: Buffer, network?: Network): string {
243149
// TODO: Network
@@ -267,24 +173,6 @@ export function fromOutputScript(output: Buffer, network?: Network): string {
267173

268174
/**
269175
* encodes address to output script with network, return output script if address matched
270-
* @example
271-
* ```ts
272-
* // valid case
273-
* toOutputScript('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH', 'bicoin)
274-
* // => OP_DUP OP_HASH160 751e76e8199196d454941c45d1b3a323f1433bd6 OP_EQUALVERIFY OP_CHECKSIG
275-
*
276-
* // invalid case
277-
* toOutputScript('24kPZCmVgzfkpGdXExy56234MRHrsqQxNWE', undefined)
278-
* // => has no matching Script
279-
*
280-
* // invalid case
281-
* toOutputScript('BC1SW50QGDZ25J', { "bech32": "foo" })
282-
* // => has an invalid prefix
283-
*
284-
* // invalid case
285-
* toOutputScript('bc1rw5uspcuh', undefined)
286-
* // => has no matching Script
287-
* ```
288176
*/
289177
export function toOutputScript(address: string, network?: Network): Buffer {
290178
network = network || networks.bitcoin;

0 commit comments

Comments
 (0)