mainnet-js 1.1.34 → 2.0.1
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-1.1.34.js → mainnet-2.0.1.js} +26 -338
- package/dist/module/db/SqlProvider.d.ts +2 -2
- package/dist/module/db/SqlProvider.d.ts.map +1 -1
- package/dist/module/db/SqlProvider.js +6 -24
- package/dist/module/db/SqlProvider.js.map +1 -1
- package/dist/module/index.d.ts +0 -3
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +3 -6
- package/dist/module/index.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +4 -8
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +6 -10
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/util/deriveCashaddr.d.ts +1 -0
- package/dist/module/util/deriveCashaddr.d.ts.map +1 -1
- package/dist/module/util/deriveCashaddr.js +8 -1
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/module/wallet/Base.d.ts +1 -1
- package/dist/module/wallet/Base.js +1 -1
- package/dist/module/wallet/Bcmr.d.ts +3 -1
- package/dist/module/wallet/Bcmr.d.ts.map +1 -1
- package/dist/module/wallet/Bcmr.js +4 -8
- package/dist/module/wallet/Bcmr.js.map +1 -1
- package/dist/module/wallet/Util.d.ts +2 -2
- package/dist/module/wallet/Util.js +2 -2
- package/dist/module/wallet/Wif.d.ts +0 -28
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +2 -109
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/createWallet.d.ts +0 -12
- package/dist/module/wallet/createWallet.d.ts.map +1 -1
- package/dist/module/wallet/createWallet.js +0 -43
- package/dist/module/wallet/createWallet.js.map +1 -1
- package/dist/module/wallet/interface.d.ts +0 -2
- package/dist/module/wallet/interface.d.ts.map +1 -1
- package/dist/module/webhook/Webhook.d.ts +1 -6
- package/dist/module/webhook/Webhook.d.ts.map +1 -1
- package/dist/module/webhook/Webhook.js +0 -4
- package/dist/module/webhook/Webhook.js.map +1 -1
- package/dist/module/webhook/index.d.ts +0 -1
- package/dist/module/webhook/index.d.ts.map +1 -1
- package/dist/module/webhook/index.js +0 -1
- package/dist/module/webhook/index.js.map +1 -1
- package/dist/module/webhook/interface.d.ts +0 -1
- package/dist/module/webhook/interface.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -10
- package/src/db/SqlProvider.test.ts +2 -18
- package/src/db/SqlProvider.ts +5 -26
- package/src/index.ts +3 -7
- package/src/transaction/Wif.ts +2 -19
- package/src/util/deriveCashaddr.test.ts +8 -0
- package/src/util/deriveCashaddr.ts +9 -0
- package/src/wallet/Base.ts +1 -1
- package/src/wallet/Bcmr.ts +4 -9
- package/src/wallet/Util.ts +2 -2
- package/src/wallet/Wif.test.ts +0 -23
- package/src/wallet/Wif.ts +2 -148
- package/src/wallet/createWallet.ts +0 -53
- package/src/wallet/interface.ts +0 -2
- package/src/webhook/Webhook.ts +4 -10
- package/src/webhook/index.ts +0 -1
- package/src/webhook/interface.ts +0 -1
- package/webpack.config.cjs +7 -7
- package/dist/module/slp/GsppProvider.d.ts +0 -55
- package/dist/module/slp/GsppProvider.d.ts.map +0 -1
- package/dist/module/slp/GsppProvider.js +0 -204
- package/dist/module/slp/GsppProvider.js.map +0 -1
- package/dist/module/slp/SlpDbProvider.d.ts +0 -52
- package/dist/module/slp/SlpDbProvider.d.ts.map +0 -1
- package/dist/module/slp/SlpDbProvider.js +0 -175
- package/dist/module/slp/SlpDbProvider.js.map +0 -1
- package/dist/module/slp/SlpDbTemplates.d.ts +0 -313
- package/dist/module/slp/SlpDbTemplates.d.ts.map +0 -1
- package/dist/module/slp/SlpDbTemplates.js +0 -375
- package/dist/module/slp/SlpDbTemplates.js.map +0 -1
- package/dist/module/slp/SlpLibAuth.d.ts +0 -210
- package/dist/module/slp/SlpLibAuth.d.ts.map +0 -1
- package/dist/module/slp/SlpLibAuth.js +0 -451
- package/dist/module/slp/SlpLibAuth.js.map +0 -1
- package/dist/module/slp/SlpProvider.d.ts +0 -24
- package/dist/module/slp/SlpProvider.d.ts.map +0 -1
- package/dist/module/slp/SlpProvider.js +0 -29
- package/dist/module/slp/SlpProvider.js.map +0 -1
- package/dist/module/slp/index.d.ts +0 -6
- package/dist/module/slp/index.d.ts.map +0 -1
- package/dist/module/slp/index.js +0 -5
- package/dist/module/slp/index.js.map +0 -1
- package/dist/module/slp/interface.d.ts +0 -114
- package/dist/module/slp/interface.d.ts.map +0 -1
- package/dist/module/slp/interface.js +0 -7
- package/dist/module/slp/interface.js.map +0 -1
- package/dist/module/util/bchaddr.d.ts +0 -2
- package/dist/module/util/bchaddr.d.ts.map +0 -1
- package/dist/module/util/bchaddr.js +0 -16
- package/dist/module/util/bchaddr.js.map +0 -1
- package/dist/module/wallet/Slp.d.ts +0 -431
- package/dist/module/wallet/Slp.d.ts.map +0 -1
- package/dist/module/wallet/Slp.js +0 -770
- package/dist/module/wallet/Slp.js.map +0 -1
- package/dist/module/webhook/WebhookSlp.d.ts +0 -15
- package/dist/module/webhook/WebhookSlp.d.ts.map +0 -1
- package/dist/module/webhook/WebhookSlp.js +0 -100
- package/dist/module/webhook/WebhookSlp.js.map +0 -1
- package/src/slp/GsppProvider.test.ts +0 -40
- package/src/slp/GsppProvider.ts +0 -329
- package/src/slp/SlpDbProvider.test.ts +0 -27
- package/src/slp/SlpDbProvider.ts +0 -291
- package/src/slp/SlpDbTemplates.ts +0 -400
- package/src/slp/SlpLibAuth.test.ts +0 -162
- package/src/slp/SlpLibAuth.ts +0 -532
- package/src/slp/SlpProvider.ts +0 -100
- package/src/slp/index.ts +0 -6
- package/src/slp/interface.ts +0 -128
- package/src/util/bchaddr.test.ts +0 -27
- package/src/util/bchaddr.ts +0 -27
- package/src/wallet/Slp.test.headless.js +0 -120
- package/src/wallet/Slp.test.ts +0 -1000
- package/src/wallet/Slp.ts +0 -1014
- package/src/webhook/WebhookSlp.test.ts +0 -288
- package/src/webhook/WebhookSlp.ts +0 -123
package/src/wallet/Wif.ts
CHANGED
|
@@ -77,20 +77,7 @@ import { sumTokenAmounts, sumUtxoValue } from "../util/sumUtxoValue.js";
|
|
|
77
77
|
import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts.js";
|
|
78
78
|
import { ElectrumRawTransaction } from "../network/interface.js";
|
|
79
79
|
import { getRelayFeeCache } from "../network/getRelayFeeCache.js";
|
|
80
|
-
import {
|
|
81
|
-
RegTestSlp,
|
|
82
|
-
RegTestWatchSlp,
|
|
83
|
-
RegTestWifSlp,
|
|
84
|
-
Slp,
|
|
85
|
-
TestNetSlp,
|
|
86
|
-
TestNetWatchSlp,
|
|
87
|
-
TestNetWifSlp,
|
|
88
|
-
WatchSlp,
|
|
89
|
-
WifSlp,
|
|
90
|
-
} from "./Slp.js";
|
|
91
80
|
import axios from "axios";
|
|
92
|
-
import { SlpSendResponse } from "../slp/interface.js";
|
|
93
|
-
import { toCashAddress } from "../util/bchaddr.js";
|
|
94
81
|
import {
|
|
95
82
|
RegTestUtil,
|
|
96
83
|
RegTestWatchUtil,
|
|
@@ -137,28 +124,11 @@ export class Wallet extends BaseWallet {
|
|
|
137
124
|
publicKey?: Uint8Array;
|
|
138
125
|
publicKeyHash?: Uint8Array;
|
|
139
126
|
networkPrefix: CashAddressNetworkPrefix;
|
|
140
|
-
_slp?: Slp;
|
|
141
|
-
_slpAware: boolean = false; // a flag which activates utxo checking against an external slp indexer
|
|
142
127
|
_slpSemiAware: boolean = false; // a flag which requires an utxo to have more than 546 sats to be spendable and counted in the balance
|
|
143
128
|
_util?: Util;
|
|
144
129
|
static signedMessage: SignedMessageI = new SignedMessage();
|
|
145
130
|
|
|
146
131
|
//#region Accessors
|
|
147
|
-
// interface to slp functions. see Slp.ts
|
|
148
|
-
public get slp() {
|
|
149
|
-
if (!this._slp) {
|
|
150
|
-
this._slp = new Slp(this);
|
|
151
|
-
this._slpAware = true;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return this._slp;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// interface to slp functions. see Slp.ts
|
|
158
|
-
public static get slp() {
|
|
159
|
-
return Slp;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
132
|
// interface to util functions. see Util.ts
|
|
163
133
|
public get util() {
|
|
164
134
|
if (!this._util) {
|
|
@@ -173,11 +143,6 @@ export class Wallet extends BaseWallet {
|
|
|
173
143
|
return Util;
|
|
174
144
|
}
|
|
175
145
|
|
|
176
|
-
public slpAware(value: boolean = true): Wallet {
|
|
177
|
-
this._slpAware = value;
|
|
178
|
-
return this;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
146
|
public slpSemiAware(value: boolean = true): Wallet {
|
|
182
147
|
this._slpSemiAware = value;
|
|
183
148
|
return this;
|
|
@@ -346,23 +311,6 @@ export class Wallet extends BaseWallet {
|
|
|
346
311
|
address
|
|
347
312
|
) as InstanceType<T>;
|
|
348
313
|
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* fromSlpaddr - create an SLP aware watch-only wallet in the network derived from the address
|
|
352
|
-
*
|
|
353
|
-
* such kind of wallet does not have a private key and is unable to spend any funds
|
|
354
|
-
* however it still allows to use many utility functions such as getting and watching balance, etc.
|
|
355
|
-
*
|
|
356
|
-
* @param address slpaddress of a wallet
|
|
357
|
-
*
|
|
358
|
-
* @returns instantiated wallet
|
|
359
|
-
*/
|
|
360
|
-
public static async fromSlpaddr<T extends typeof Wallet>(
|
|
361
|
-
this: T,
|
|
362
|
-
address: string
|
|
363
|
-
): Promise<InstanceType<T>> {
|
|
364
|
-
return this.fromCashaddr(toCashAddress(address)) as InstanceType<T>;
|
|
365
|
-
}
|
|
366
314
|
//#endregion Constructors and Statics
|
|
367
315
|
|
|
368
316
|
//#region Protected implementations
|
|
@@ -639,18 +587,7 @@ export class Wallet extends BaseWallet {
|
|
|
639
587
|
address = this.cashaddr!;
|
|
640
588
|
}
|
|
641
589
|
|
|
642
|
-
if (this.
|
|
643
|
-
const [bchUtxos, slpOutpoints] = await Promise.all([
|
|
644
|
-
this.provider!.getUtxos(address),
|
|
645
|
-
this.slp.getSlpOutpoints(),
|
|
646
|
-
]);
|
|
647
|
-
return bchUtxos.filter(
|
|
648
|
-
(bchutxo) =>
|
|
649
|
-
slpOutpoints.findIndex(
|
|
650
|
-
(slpOutpoint) => `${bchutxo.txid}:${bchutxo.vout}` === slpOutpoint
|
|
651
|
-
) === -1
|
|
652
|
-
);
|
|
653
|
-
} else if (this._slpSemiAware) {
|
|
590
|
+
if (this._slpSemiAware) {
|
|
654
591
|
const bchUtxos: UtxoI[] = await this.provider!.getUtxos(address);
|
|
655
592
|
return bchUtxos.filter(
|
|
656
593
|
(bchutxo) => bchutxo.satoshis > DUST_UTXO_THRESHOLD
|
|
@@ -866,10 +803,6 @@ export class Wallet extends BaseWallet {
|
|
|
866
803
|
throw Error("attempted to send without a cashaddr");
|
|
867
804
|
}
|
|
868
805
|
|
|
869
|
-
if (params.options && params.options.slpAware) {
|
|
870
|
-
this._slpAware = true;
|
|
871
|
-
}
|
|
872
|
-
|
|
873
806
|
if (params.options && params.options.slpSemiAware) {
|
|
874
807
|
this._slpSemiAware = true;
|
|
875
808
|
}
|
|
@@ -920,7 +853,6 @@ export class Wallet extends BaseWallet {
|
|
|
920
853
|
privateKey: this.privateKey ?? Uint8Array.from([]),
|
|
921
854
|
sourceAddress: this.cashaddr!,
|
|
922
855
|
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
923
|
-
slpOutputs: [],
|
|
924
856
|
feePaidBy: feePaidBy,
|
|
925
857
|
});
|
|
926
858
|
const spendableAmount = sumUtxoValue(fundingUtxos);
|
|
@@ -1097,10 +1029,6 @@ export class Wallet extends BaseWallet {
|
|
|
1097
1029
|
throw Error("attempted to send without a cashaddr");
|
|
1098
1030
|
}
|
|
1099
1031
|
|
|
1100
|
-
if (options && options.slpAware) {
|
|
1101
|
-
this._slpAware = true;
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
1032
|
if (options && options.slpSemiAware) {
|
|
1105
1033
|
this._slpSemiAware = true;
|
|
1106
1034
|
}
|
|
@@ -1238,7 +1166,6 @@ export class Wallet extends BaseWallet {
|
|
|
1238
1166
|
privateKey: this.privateKey ?? Uint8Array.from([]),
|
|
1239
1167
|
sourceAddress: this.cashaddr!,
|
|
1240
1168
|
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
1241
|
-
slpOutputs: [],
|
|
1242
1169
|
feePaidBy: feePaidBy,
|
|
1243
1170
|
});
|
|
1244
1171
|
|
|
@@ -1262,7 +1189,6 @@ export class Wallet extends BaseWallet {
|
|
|
1262
1189
|
privateKey: this.privateKey ?? Uint8Array.from([]),
|
|
1263
1190
|
sourceAddress: this.cashaddr!,
|
|
1264
1191
|
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
1265
|
-
slpOutputs: [],
|
|
1266
1192
|
feePaidBy: feePaidBy,
|
|
1267
1193
|
});
|
|
1268
1194
|
const { encodedTransaction, sourceOutputs } = await buildEncodedTransaction(
|
|
@@ -1273,7 +1199,6 @@ export class Wallet extends BaseWallet {
|
|
|
1273
1199
|
sourceAddress: this.cashaddr!,
|
|
1274
1200
|
fee,
|
|
1275
1201
|
discardChange,
|
|
1276
|
-
slpOutputs: [],
|
|
1277
1202
|
feePaidBy,
|
|
1278
1203
|
changeAddress,
|
|
1279
1204
|
buildUnsigned: options?.buildUnsigned === true,
|
|
@@ -1857,38 +1782,7 @@ export class TestNetWallet extends Wallet {
|
|
|
1857
1782
|
`${TestNetWallet.faucetServer}/faucet/get_addresses`
|
|
1858
1783
|
);
|
|
1859
1784
|
const data = response.data;
|
|
1860
|
-
return await this.
|
|
1861
|
-
} catch (e: any) {
|
|
1862
|
-
console.log(e);
|
|
1863
|
-
console.log(e.response ? e.response.data : "");
|
|
1864
|
-
throw e;
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
// will receive 10 testnet tokens, rate limits apply
|
|
1869
|
-
async getTestnetSlp(tokenId: string): Promise<string> {
|
|
1870
|
-
try {
|
|
1871
|
-
const response = await axios.post(
|
|
1872
|
-
`${TestNetWallet.faucetServer}/faucet/get_testnet_slp`,
|
|
1873
|
-
{ slpaddr: this.slp.slpaddr, tokenId: tokenId }
|
|
1874
|
-
);
|
|
1875
|
-
const data = response.data;
|
|
1876
|
-
return data.txId;
|
|
1877
|
-
} catch (e) {
|
|
1878
|
-
//console.log(e);
|
|
1879
|
-
//console.log(e.response ? e.response.data : "");
|
|
1880
|
-
throw e;
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
|
|
1884
|
-
// be nice and return them back
|
|
1885
|
-
async returnTestnetSlp(tokenId: string): Promise<SlpSendResponse> {
|
|
1886
|
-
try {
|
|
1887
|
-
const response = await axios.post(
|
|
1888
|
-
`${TestNetWallet.faucetServer}/faucet/get_addresses`
|
|
1889
|
-
);
|
|
1890
|
-
const data = response.data;
|
|
1891
|
-
return await this.slp.sendMax(data.slptest, tokenId);
|
|
1785
|
+
return await this.sendMax(data.bchtest);
|
|
1892
1786
|
} catch (e: any) {
|
|
1893
1787
|
console.log(e);
|
|
1894
1788
|
console.log(e.response ? e.response.data : "");
|
|
@@ -1896,11 +1790,6 @@ export class TestNetWallet extends Wallet {
|
|
|
1896
1790
|
}
|
|
1897
1791
|
}
|
|
1898
1792
|
|
|
1899
|
-
// interface to static slp functions. see Slp.ts
|
|
1900
|
-
public static get slp() {
|
|
1901
|
-
return TestNetSlp;
|
|
1902
|
-
}
|
|
1903
|
-
|
|
1904
1793
|
// interface to static util functions. see Util.ts
|
|
1905
1794
|
public static get util() {
|
|
1906
1795
|
return TestNetUtil;
|
|
@@ -1916,11 +1805,6 @@ export class RegTestWallet extends Wallet {
|
|
|
1916
1805
|
super(name, NetworkType.Regtest);
|
|
1917
1806
|
}
|
|
1918
1807
|
|
|
1919
|
-
// interface to static slp functions. see Slp.ts
|
|
1920
|
-
public static get slp() {
|
|
1921
|
-
return RegTestSlp;
|
|
1922
|
-
}
|
|
1923
|
-
|
|
1924
1808
|
// interface to static util functions. see Util.ts
|
|
1925
1809
|
public static get util() {
|
|
1926
1810
|
return RegTestUtil;
|
|
@@ -1937,11 +1821,6 @@ export class WifWallet extends Wallet {
|
|
|
1937
1821
|
super(name, NetworkType.Mainnet, WalletTypeEnum.Wif);
|
|
1938
1822
|
}
|
|
1939
1823
|
|
|
1940
|
-
// interface to static slp functions. see Slp.ts
|
|
1941
|
-
public static get slp() {
|
|
1942
|
-
return WifSlp;
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
1824
|
// interface to static util functions. see Util.ts
|
|
1946
1825
|
public static get util() {
|
|
1947
1826
|
return WifUtil;
|
|
@@ -1958,11 +1837,6 @@ export class TestNetWifWallet extends Wallet {
|
|
|
1958
1837
|
super(name, NetworkType.Testnet, WalletTypeEnum.Wif);
|
|
1959
1838
|
}
|
|
1960
1839
|
|
|
1961
|
-
// interface to static slp functions. see Slp.ts
|
|
1962
|
-
public static get slp() {
|
|
1963
|
-
return TestNetWifSlp;
|
|
1964
|
-
}
|
|
1965
|
-
|
|
1966
1840
|
// interface to static util functions. see Util.ts
|
|
1967
1841
|
public static get util() {
|
|
1968
1842
|
return TestNetWifUtil;
|
|
@@ -1979,11 +1853,6 @@ export class RegTestWifWallet extends Wallet {
|
|
|
1979
1853
|
super(name, NetworkType.Regtest, WalletTypeEnum.Wif);
|
|
1980
1854
|
}
|
|
1981
1855
|
|
|
1982
|
-
// interface to static slp functions. see Slp.ts
|
|
1983
|
-
public static get slp() {
|
|
1984
|
-
return RegTestWifSlp;
|
|
1985
|
-
}
|
|
1986
|
-
|
|
1987
1856
|
// interface to static util functions. see Util.ts
|
|
1988
1857
|
public static get util() {
|
|
1989
1858
|
return RegTestWifUtil;
|
|
@@ -2000,11 +1869,6 @@ export class WatchWallet extends Wallet {
|
|
|
2000
1869
|
super(name, NetworkType.Mainnet, WalletTypeEnum.Watch);
|
|
2001
1870
|
}
|
|
2002
1871
|
|
|
2003
|
-
// interface to static slp functions. see Slp.ts
|
|
2004
|
-
public static get slp() {
|
|
2005
|
-
return WatchSlp;
|
|
2006
|
-
}
|
|
2007
|
-
|
|
2008
1872
|
// interface to static util functions. see Util.ts
|
|
2009
1873
|
public static get util() {
|
|
2010
1874
|
return WatchUtil;
|
|
@@ -2021,11 +1885,6 @@ export class TestNetWatchWallet extends Wallet {
|
|
|
2021
1885
|
super(name, NetworkType.Testnet, WalletTypeEnum.Watch);
|
|
2022
1886
|
}
|
|
2023
1887
|
|
|
2024
|
-
// interface to static slp functions. see Slp.ts
|
|
2025
|
-
public static get slp() {
|
|
2026
|
-
return TestNetWatchSlp;
|
|
2027
|
-
}
|
|
2028
|
-
|
|
2029
1888
|
// interface to static util functions. see Util.ts
|
|
2030
1889
|
public static get util() {
|
|
2031
1890
|
return TestNetWatchUtil;
|
|
@@ -2042,11 +1901,6 @@ export class RegTestWatchWallet extends Wallet {
|
|
|
2042
1901
|
super(name, NetworkType.Regtest, WalletTypeEnum.Watch);
|
|
2043
1902
|
}
|
|
2044
1903
|
|
|
2045
|
-
// interface to static slp functions. see Slp.ts
|
|
2046
|
-
public static get slp() {
|
|
2047
|
-
return RegTestWatchSlp;
|
|
2048
|
-
}
|
|
2049
|
-
|
|
2050
1904
|
// interface to static util functions. see Util.ts
|
|
2051
1905
|
public static get util() {
|
|
2052
1906
|
return RegTestWatchUtil;
|
|
@@ -164,41 +164,6 @@ export async function createWallet(body: WalletRequestI): Promise<Wallet> {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
/**
|
|
168
|
-
* Create a new SLP aware wallet
|
|
169
|
-
* @param body A wallet request object
|
|
170
|
-
* @returns A promise to a new wallet object
|
|
171
|
-
*/
|
|
172
|
-
export async function createSlpWallet(body: WalletRequestI): Promise<Wallet> {
|
|
173
|
-
let wallet;
|
|
174
|
-
let walletType = body.type ? body.type : "seed";
|
|
175
|
-
let networkType = body.network ? body.network : "mainnet";
|
|
176
|
-
|
|
177
|
-
// Named wallets are saved in the database
|
|
178
|
-
if (body.name && body.name.length > 0) {
|
|
179
|
-
wallet = await walletClassMap[walletType][networkType]().slp.named(
|
|
180
|
-
body.name
|
|
181
|
-
);
|
|
182
|
-
if (wallet.network != networkType) {
|
|
183
|
-
throw Error(
|
|
184
|
-
`A wallet already exists with name ${body.name}, but with network ${wallet.network} not ${body.network}, per request`
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
if (wallet.walletType != walletType) {
|
|
188
|
-
throw Error(
|
|
189
|
-
`A wallet already exists with name ${body.name}, but with type ${wallet.walletType} not ${body.type}, per request`
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
return wallet;
|
|
193
|
-
}
|
|
194
|
-
// This handles unsaved/unnamed wallets
|
|
195
|
-
else {
|
|
196
|
-
wallet = await walletClassMap[walletType][networkType]().slp.newRandom();
|
|
197
|
-
wallet.walletType = walletType;
|
|
198
|
-
return wallet;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
167
|
/**
|
|
203
168
|
* Create a new wallet
|
|
204
169
|
* @param walletRequest A wallet request object
|
|
@@ -215,22 +180,6 @@ export async function createWalletResponse(
|
|
|
215
180
|
}
|
|
216
181
|
}
|
|
217
182
|
|
|
218
|
-
/**
|
|
219
|
-
* Create a new SLP aware wallet
|
|
220
|
-
* @param walletRequest A wallet request object
|
|
221
|
-
* @returns A new wallet object
|
|
222
|
-
*/
|
|
223
|
-
export async function createSlpWalletResponse(
|
|
224
|
-
walletRequest: WalletRequestI
|
|
225
|
-
): Promise<WalletResponseI> {
|
|
226
|
-
let wallet = await createSlpWallet(walletRequest);
|
|
227
|
-
if (wallet) {
|
|
228
|
-
return asJsonResponse(wallet);
|
|
229
|
-
} else {
|
|
230
|
-
throw Error("Error creating wallet");
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
183
|
/**
|
|
235
184
|
* asJsonResponse return a wallet as json
|
|
236
185
|
* @param wallet A wallet object
|
|
@@ -241,7 +190,6 @@ function asJsonResponse(wallet: Wallet): WalletResponseI {
|
|
|
241
190
|
return {
|
|
242
191
|
name: wallet.name,
|
|
243
192
|
cashaddr: wallet.cashaddr as string,
|
|
244
|
-
slpaddr: wallet.slp.slpaddr,
|
|
245
193
|
walletId: wallet.toString(),
|
|
246
194
|
...wallet.getSeed(),
|
|
247
195
|
network: wallet.network as any,
|
|
@@ -250,7 +198,6 @@ function asJsonResponse(wallet: Wallet): WalletResponseI {
|
|
|
250
198
|
return {
|
|
251
199
|
name: wallet.name,
|
|
252
200
|
cashaddr: wallet.cashaddr as string,
|
|
253
|
-
slpaddr: wallet.slp.slpaddr,
|
|
254
201
|
walletId: wallet.toString(),
|
|
255
202
|
wif: wallet.privateKeyWif,
|
|
256
203
|
network: wallet.network as any,
|
package/src/wallet/interface.ts
CHANGED
|
@@ -16,7 +16,6 @@ export interface WalletRequestI {
|
|
|
16
16
|
export interface WalletResponseI {
|
|
17
17
|
name: string;
|
|
18
18
|
cashaddr?: string;
|
|
19
|
-
slpaddr?: string;
|
|
20
19
|
address?: string;
|
|
21
20
|
walletId: string;
|
|
22
21
|
network?: NetworkEnum;
|
|
@@ -48,7 +47,6 @@ export interface WalletInfoI {
|
|
|
48
47
|
export interface SendRequestOptionsI {
|
|
49
48
|
utxoIds?: string[] | UtxoI[];
|
|
50
49
|
changeAddress?: string;
|
|
51
|
-
slpAware?: boolean; // a flag which activates utxo checking against an external slp indexer
|
|
52
50
|
slpSemiAware?: boolean; // a flag which requires an utxo to have more than 546 sats to be spendable and counted in the balance
|
|
53
51
|
queryBalance?: boolean;
|
|
54
52
|
awaitTransactionPropagation?: boolean;
|
package/src/webhook/Webhook.ts
CHANGED
|
@@ -8,11 +8,6 @@ export enum WebhookType {
|
|
|
8
8
|
transactionOut = "transaction:out",
|
|
9
9
|
transactionInOut = "transaction:in,out",
|
|
10
10
|
balance = "balance",
|
|
11
|
-
|
|
12
|
-
slpTransactionIn = "slptransaction:in",
|
|
13
|
-
slpTransactionOut = "slptransaction:out",
|
|
14
|
-
slpTransactionInOut = "slptransaction:in,out",
|
|
15
|
-
slpBalance = "slpbalance",
|
|
16
11
|
}
|
|
17
12
|
|
|
18
13
|
export enum WebhookRecurrence {
|
|
@@ -22,14 +17,13 @@ export enum WebhookRecurrence {
|
|
|
22
17
|
|
|
23
18
|
export class Webhook {
|
|
24
19
|
id?: number;
|
|
25
|
-
cashaddr!: string;
|
|
20
|
+
cashaddr!: string;
|
|
26
21
|
type!: string;
|
|
27
22
|
recurrence!: string;
|
|
28
23
|
url!: string;
|
|
29
|
-
status!: string;
|
|
30
|
-
last_height!: number;
|
|
31
|
-
tx_seen!: TxI[];
|
|
32
|
-
tokenId?: string; // slp only
|
|
24
|
+
status!: string;
|
|
25
|
+
last_height!: number;
|
|
26
|
+
tx_seen!: TxI[];
|
|
33
27
|
expires_at!: Date;
|
|
34
28
|
|
|
35
29
|
db!: SqlProvider;
|
package/src/webhook/index.ts
CHANGED
package/src/webhook/interface.ts
CHANGED
package/webpack.config.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const { merge } = require("webpack-merge");
|
|
2
|
-
const path = require("path");
|
|
3
2
|
const packageJson = require("./package.json");
|
|
4
3
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
5
4
|
const InjectBodyPlugin = require("inject-body-webpack-plugin").default;
|
|
@@ -8,6 +7,7 @@ const BundleAnalyzerPlugin =
|
|
|
8
7
|
const CircularDependencyPlugin = require("circular-dependency-plugin");
|
|
9
8
|
const __basedir = require("path").resolve(__dirname, "../../");
|
|
10
9
|
|
|
10
|
+
const path = require("path");
|
|
11
11
|
const webpack = require("webpack");
|
|
12
12
|
|
|
13
13
|
const baseConfig = {
|
|
@@ -96,11 +96,6 @@ const browserConfig = {
|
|
|
96
96
|
],
|
|
97
97
|
resolve: {
|
|
98
98
|
alias: {
|
|
99
|
-
ethers$: require.resolve("ethers/lib/index.js"),
|
|
100
|
-
"@ethersproject/web$": require.resolve("@ethersproject/web/lib/index.js"),
|
|
101
|
-
"@ethersproject/contracts$": require.resolve(
|
|
102
|
-
"@ethersproject/contracts/lib/index.js"
|
|
103
|
-
),
|
|
104
99
|
bufferutil: false,
|
|
105
100
|
child_process: false,
|
|
106
101
|
crypto: false,
|
|
@@ -119,10 +114,15 @@ const browserConfig = {
|
|
|
119
114
|
pg: false,
|
|
120
115
|
"pg-format": false,
|
|
121
116
|
"pg-native": false,
|
|
122
|
-
solc: false,
|
|
123
117
|
tls: false,
|
|
124
118
|
url: false,
|
|
125
119
|
zlib: false,
|
|
120
|
+
[path.resolve(__dirname, "./src/webhook/index.ts")]: false,
|
|
121
|
+
[path.resolve(__dirname, "./src/webhook/interface.ts")]: false,
|
|
122
|
+
[path.resolve(__dirname, "./src/webhook/Webhook.ts")]: false,
|
|
123
|
+
[path.resolve(__dirname, "./src/webhook/WebhookBch.ts")]: false,
|
|
124
|
+
[path.resolve(__dirname, "./src/webhook/WebhookWorker.ts")]: false,
|
|
125
|
+
[path.resolve(__dirname, "./src/db/SqlProvider.ts")]: false,
|
|
126
126
|
},
|
|
127
127
|
fallback: {
|
|
128
128
|
stream: require.resolve("stream-browserify"),
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Network } from "../interface.js";
|
|
2
|
-
import { SlpTokenBalance, SlpTokenInfo, SlpTxI, SlpUtxoI } from "./interface.js";
|
|
3
|
-
import BigNumber from "bignumber.js";
|
|
4
|
-
import { SlpCancelWatchFn, SlpProvider, SlpWatchBalanceCallback, SlpWatchTransactionCallback } from "./SlpProvider.js";
|
|
5
|
-
export declare class GsppProvider implements SlpProvider {
|
|
6
|
-
network: Network;
|
|
7
|
-
static defaultServers: {
|
|
8
|
-
mainnet: {
|
|
9
|
-
dataSource: string;
|
|
10
|
-
eventSource: string;
|
|
11
|
-
};
|
|
12
|
-
testnet: {
|
|
13
|
-
dataSource: string;
|
|
14
|
-
eventSource: string;
|
|
15
|
-
};
|
|
16
|
-
regtest: {
|
|
17
|
-
dataSource: string;
|
|
18
|
-
eventSource: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
servers: {
|
|
22
|
-
mainnet: {
|
|
23
|
-
dataSource: string;
|
|
24
|
-
eventSource: string;
|
|
25
|
-
};
|
|
26
|
-
testnet: {
|
|
27
|
-
dataSource: string;
|
|
28
|
-
eventSource: string;
|
|
29
|
-
};
|
|
30
|
-
regtest: {
|
|
31
|
-
dataSource: string;
|
|
32
|
-
eventSource: string;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
caching: boolean;
|
|
36
|
-
constructor(network?: Network);
|
|
37
|
-
SlpOutpoints(slpaddr: string): Promise<String[]>;
|
|
38
|
-
SlpUtxos(slpaddr: string): Promise<SlpUtxoI[]>;
|
|
39
|
-
SlpSpendableUtxos(slpaddr: string, tokenId?: string): Promise<SlpUtxoI[]>;
|
|
40
|
-
SlpBatonUtxos(slpaddr: string, tokenId?: string): Promise<SlpUtxoI[]>;
|
|
41
|
-
SlpTokenInfo(tokenId: string): Promise<SlpTokenInfo | undefined>;
|
|
42
|
-
SlpAllTokenBalances(slpaddr: string): Promise<SlpTokenBalance[]>;
|
|
43
|
-
SlpTokenBalance(slpaddr: string, tokenId: string): Promise<SlpTokenBalance>;
|
|
44
|
-
SlpAddressTransactionHistory(_slpaddr: string, _tokenId?: string, _limit?: number, _skip?: number): Promise<SlpTxI[]>;
|
|
45
|
-
SlpWaitForTransaction(slpaddr: string, tokenId?: string): Promise<SlpTxI>;
|
|
46
|
-
SlpWaitForBalance(value: BigNumber.Value, slpaddr: string, tokenId: string): Promise<SlpTokenBalance>;
|
|
47
|
-
SlpWatchBalance(callback: SlpWatchBalanceCallback, slpaddr: string, tokenId: string): SlpCancelWatchFn;
|
|
48
|
-
SlpWatchTransactions(callback: SlpWatchTransactionCallback, slpaddr?: string, tokenId?: string): SlpCancelWatchFn;
|
|
49
|
-
GsppQuery(queryObject: any, endpoint?: string): Promise<any>;
|
|
50
|
-
SlpSocketEventSource(queryObject: any): EventSource;
|
|
51
|
-
}
|
|
52
|
-
export declare function _convertBalanceBigNumbers(balances: SlpTokenBalance[]): SlpTokenBalance[];
|
|
53
|
-
export declare function _convertUtxoBigNumbers(utxos: SlpUtxoI[]): SlpUtxoI[];
|
|
54
|
-
export declare function _convertSlpTokenInfo(tokenInfo: SlpTokenInfo | undefined): SlpTokenInfo | undefined;
|
|
55
|
-
//# sourceMappingURL=GsppProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GsppProvider.d.ts","sourceRoot":"","sources":["../../../src/slp/GsppProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAO,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAEL,eAAe,EACf,YAAY,EACZ,MAAM,EACN,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,2BAA2B,EAE5B,MAAM,kBAAkB,CAAC;AAW1B,qBAAa,YAAa,YAAW,WAAW;IAoB3B,OAAO,EAAE,OAAO;IAnBnC,OAAc,cAAc;;;;;;;;;;;;;MAa1B;IAEK,OAAO;;;;;;;;;;;;;MAAsC;IAE7C,OAAO,EAAE,OAAO,CAAS;gBAEb,OAAO,GAAE,OAAyB;IAkB/C,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOhD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAa9C,iBAAiB,CACrB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,QAAQ,EAAE,CAAC;IAQhB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAQrE,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAShE,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAYhE,eAAe,CACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,eAAe,CAAC;IAiBrB,4BAA4B,CAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,GAAE,MAAY,EACpB,KAAK,GAAE,MAAU,GAChB,OAAO,CAAC,MAAM,EAAE,CAAC;IAKd,qBAAqB,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;IAcZ,iBAAiB,CACrB,KAAK,EAAE,SAAS,CAAC,KAAK,EACtB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,eAAe,CAAC;IAgB3B,eAAe,CACb,QAAQ,EAAE,uBAAuB,EACjC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,gBAAgB;IAYnB,oBAAoB,CAClB,QAAQ,EAAE,2BAA2B,EACrC,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,GACf,gBAAgB;IA4BZ,SAAS,CAAC,WAAW,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IA0B5D,oBAAoB,CAAC,WAAW,EAAE,GAAG,GAAG,WAAW;CAM3D;AA6BD,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,eAAe,EAAE,GAC1B,eAAe,EAAE,CAKnB;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAMpE;AAED,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,YAAY,GAAG,SAAS,GAClC,YAAY,GAAG,SAAS,CAS1B"}
|