mainnet-js 2.7.4 → 2.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.html +1 -1
- package/dist/{mainnet-2.7.4.js → mainnet-2.7.6.js} +15 -206
- package/dist/module/mine/mine.d.ts.map +1 -1
- package/dist/module/mine/mine.js +1 -1
- package/dist/module/mine/mine.js.map +1 -1
- package/dist/module/util/deriveCashaddr.d.ts +4 -2
- package/dist/module/util/deriveCashaddr.d.ts.map +1 -1
- package/dist/module/util/deriveCashaddr.js +32 -45
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/mine/mine.ts +2 -2
- package/src/util/deriveCashaddr.test.ts +121 -8
- package/src/util/deriveCashaddr.ts +40 -68
- package/dist/_67af-2.7.4.js +0 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mine.d.ts","sourceRoot":"","sources":["../../../src/mine/mine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mine.d.ts","sourceRoot":"","sources":["../../../src/mine/mine.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,wBAAsB,IAAI,CAAC,EACzB,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,gBAqBA"}
|
package/dist/module/mine/mine.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { browserNotSupported } from "../util/browserNotSupported.js";
|
|
2
|
+
import child_process from "child_process";
|
|
2
3
|
/**
|
|
3
4
|
* Mine blocks to a regtest address
|
|
4
5
|
*
|
|
@@ -11,7 +12,6 @@ import { browserNotSupported } from "../util/browserNotSupported.js";
|
|
|
11
12
|
export async function mine({ cashaddr, blocks, }) {
|
|
12
13
|
// node only
|
|
13
14
|
browserNotSupported();
|
|
14
|
-
const child_process = await import("child_process");
|
|
15
15
|
const generateArgs = [
|
|
16
16
|
`exec`,
|
|
17
17
|
`bitcoind`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mine.js","sourceRoot":"","sources":["../../../src/mine/mine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE;;;;;;;;GAQG;AAEH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,EACzB,QAAQ,EACR,MAAM,GAIP;IACC,YAAY;IACZ,mBAAmB,EAAE,CAAC;IAEtB,MAAM,
|
|
1
|
+
{"version":3,"file":"mine.js","sourceRoot":"","sources":["../../../src/mine/mine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,aAAa,MAAM,eAAe,CAAC;AAE1C;;;;;;;;GAQG;AAEH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,EACzB,QAAQ,EACR,MAAM,GAIP;IACC,YAAY;IACZ,mBAAmB,EAAE,CAAC;IAEtB,MAAM,YAAY,GAAG;QACnB,MAAM;QACN,UAAU;QACV,aAAa;QACb,gBAAgB,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QACtC,aAAa,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QACnC,iBAAiB,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QACvC,aAAa,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QACnC,mBAAmB;QACnB,MAAM;QACN,QAAQ;KACT,CAAC;IACF,MAAM,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAmB,CAAC,CAAC;IACnE,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { CashAddressNetworkPrefix } from "@bitauth/libauth";
|
|
2
|
+
import { Network } from "../interface.js";
|
|
2
3
|
export declare function isValidAddress(cashaddr: string): boolean;
|
|
3
4
|
export declare function deriveCashaddr(privateKey: Uint8Array, networkPrefix: CashAddressNetworkPrefix): string;
|
|
4
5
|
export declare function deriveTokenaddr(key: Uint8Array, networkPrefix: CashAddressNetworkPrefix): string;
|
|
5
|
-
export declare function toCashaddr(
|
|
6
|
-
export declare function toTokenaddr(
|
|
6
|
+
export declare function toCashaddr(address: string): string;
|
|
7
|
+
export declare function toTokenaddr(address: string): string;
|
|
7
8
|
export declare function isTokenaddr(address: string): boolean;
|
|
9
|
+
export declare function convertAddress(address: string, network?: Network, withTokens?: boolean | undefined): string;
|
|
8
10
|
export declare function checkTokenaddr(cashaddr: string, enforce: boolean): void;
|
|
9
11
|
//# sourceMappingURL=deriveCashaddr.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deriveCashaddr.d.ts","sourceRoot":"","sources":["../../../src/util/deriveCashaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,
|
|
1
|
+
{"version":3,"file":"deriveCashaddr.d.ts","sourceRoot":"","sources":["../../../src/util/deriveCashaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EAMzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAOxD;AAED,wBAAgB,cAAc,CAC5B,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,wBAAwB,GACtC,MAAM,CAWR;AAED,wBAAgB,eAAe,CAC7B,GAAG,EAAE,UAAU,EACf,aAAa,EAAE,wBAAwB,GACtC,MAAM,CA+BR;AAUD,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQlD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CASnD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAIpD;AAMD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,OAAmB,EAC5B,UAAU,GAAE,OAAO,GAAG,SAAqB,GAC1C,MAAM,CAYR;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,QAIhE"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CashAddressType, decodeCashAddress, encodeCashAddress, secp256k1, } from "@bitauth/libauth";
|
|
2
|
+
import { prefixFromNetworkMap } from "../enum.js";
|
|
2
3
|
import { hash160 } from "./hash160.js";
|
|
3
4
|
export function isValidAddress(cashaddr) {
|
|
4
5
|
const result = decodeCashAddress(cashaddr);
|
|
@@ -54,62 +55,48 @@ export function deriveTokenaddr(key, networkPrefix) {
|
|
|
54
55
|
payload: publicKeyHash,
|
|
55
56
|
}).address;
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (tokenaddr.includes(":")) {
|
|
61
|
-
result = decodeCashAddressFormat(tokenaddr);
|
|
62
|
-
}
|
|
63
|
-
// otherwise, derive the network from the tokenaddr without prefix
|
|
64
|
-
else {
|
|
65
|
-
result = decodeCashAddressFormatWithoutPrefix(tokenaddr);
|
|
66
|
-
}
|
|
67
|
-
if (typeof result === "string")
|
|
58
|
+
function decodeAddress(address) {
|
|
59
|
+
const result = decodeCashAddress(address);
|
|
60
|
+
if (typeof result === "string") {
|
|
68
61
|
throw new Error(result);
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
export function toCashaddr(address) {
|
|
66
|
+
const result = decodeAddress(address);
|
|
69
67
|
return encodeCashAddress({
|
|
70
68
|
prefix: result.prefix,
|
|
71
|
-
type:
|
|
69
|
+
type: result.type.replace("WithTokens", ""),
|
|
72
70
|
payload: result.payload,
|
|
73
71
|
}).address;
|
|
74
72
|
}
|
|
75
|
-
export function toTokenaddr(
|
|
76
|
-
|
|
77
|
-
// If the address has a prefix decode it as is
|
|
78
|
-
if (cashaddr.includes(":")) {
|
|
79
|
-
result = decodeCashAddressFormat(cashaddr);
|
|
80
|
-
}
|
|
81
|
-
// otherwise, derive the network from the cashaddr without prefix
|
|
82
|
-
else {
|
|
83
|
-
result = decodeCashAddressFormatWithoutPrefix(cashaddr);
|
|
84
|
-
}
|
|
85
|
-
if (typeof result === "string")
|
|
86
|
-
throw new Error(result);
|
|
73
|
+
export function toTokenaddr(address) {
|
|
74
|
+
const result = decodeAddress(address);
|
|
87
75
|
return encodeCashAddress({
|
|
88
76
|
prefix: result.prefix,
|
|
89
|
-
type:
|
|
77
|
+
type: (result.type.replace("WithTokens", "") +
|
|
78
|
+
"WithTokens"),
|
|
90
79
|
payload: result.payload,
|
|
91
80
|
}).address;
|
|
92
81
|
}
|
|
93
82
|
export function isTokenaddr(address) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
return ([CashAddressType.p2pkhWithTokens, CashAddressType.p2shWithTokens].indexOf(type) !== -1);
|
|
83
|
+
const result = decodeAddress(address);
|
|
84
|
+
return result.type.endsWith("WithTokens");
|
|
85
|
+
}
|
|
86
|
+
// This function converts a cash address to a cash address of the specified network.
|
|
87
|
+
// If withTokens is true, it will return a token-aware address.
|
|
88
|
+
// If withTokens is false, it will return a non-token-aware address.
|
|
89
|
+
// If withTokens is undefined, it will not change the token-awareness.
|
|
90
|
+
export function convertAddress(address, network = "mainnet", withTokens = undefined) {
|
|
91
|
+
const result = decodeAddress(address);
|
|
92
|
+
return encodeCashAddress({
|
|
93
|
+
prefix: prefixFromNetworkMap[network],
|
|
94
|
+
type: withTokens === undefined
|
|
95
|
+
? result.type
|
|
96
|
+
: (result.type.replace("WithTokens", "") +
|
|
97
|
+
(withTokens ? "WithTokens" : "")),
|
|
98
|
+
payload: result.payload,
|
|
99
|
+
}).address;
|
|
113
100
|
}
|
|
114
101
|
export function checkTokenaddr(cashaddr, enforce) {
|
|
115
102
|
if (enforce && !isTokenaddr(cashaddr)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deriveCashaddr.js","sourceRoot":"","sources":["../../../src/util/deriveCashaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"deriveCashaddr.js","sourceRoot":"","sources":["../../../src/util/deriveCashaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,iBAAiB,EAEjB,iBAAiB,EACjB,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,UAAsB,EACtB,aAAuC;IAEvC,IAAI,SAAS,GAAG,SAAS,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC;IAChE,IAAI,OAAO,SAAS,KAAK,QAAQ,EA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