@ardrive/turbo-sdk 1.44.1 → 2.0.0-alpha.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/lib/cjs/cli/errors.js +1 -1
- package/lib/cjs/cli/options.js +2 -10
- package/lib/cjs/cli/utils.js +4 -13
- package/lib/cjs/common/factory.js +0 -3
- package/lib/cjs/common/folderIndex.js +1 -1
- package/lib/cjs/common/signer.js +2 -10
- package/lib/cjs/common/token/index.js +0 -5
- package/lib/cjs/types.js +0 -8
- package/lib/cjs/utils/common.js +0 -30
- package/lib/cjs/version.js +1 -1
- package/lib/esm/cli/errors.js +1 -1
- package/lib/esm/cli/options.js +2 -10
- package/lib/esm/cli/utils.js +5 -14
- package/lib/esm/common/factory.js +0 -3
- package/lib/esm/common/folderIndex.js +1 -1
- package/lib/esm/common/signer.js +0 -8
- package/lib/esm/common/token/index.js +0 -5
- package/lib/esm/types.js +0 -7
- package/lib/esm/utils/common.js +1 -28
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/options.d.ts +21 -85
- package/lib/types/cli/options.d.ts.map +1 -1
- package/lib/types/cli/types.d.ts +0 -1
- package/lib/types/cli/types.d.ts.map +1 -1
- package/lib/types/cli/utils.d.ts +1 -1
- package/lib/types/cli/utils.d.ts.map +1 -1
- package/lib/types/common/factory.d.ts.map +1 -1
- package/lib/types/common/signer.d.ts.map +1 -1
- package/lib/types/common/token/index.d.ts +0 -1
- package/lib/types/common/token/index.d.ts.map +1 -1
- package/lib/types/types.d.ts +1 -3
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/common.d.ts +0 -3
- package/lib/types/utils/common.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/lib/types/version.d.ts.map +1 -1
- package/package.json +1 -3
- package/lib/cjs/common/token/kyve.js +0 -212
- package/lib/esm/common/token/kyve.js +0 -203
- package/lib/types/common/token/kyve.d.ts +0 -84
- package/lib/types/common/token/kyve.d.ts.map +0 -1
package/lib/cjs/cli/errors.js
CHANGED
|
@@ -19,7 +19,7 @@ exports.NoWalletProvidedError = void 0;
|
|
|
19
19
|
const errors_js_1 = require("../utils/errors.js");
|
|
20
20
|
class NoWalletProvidedError extends errors_js_1.BaseError {
|
|
21
21
|
constructor() {
|
|
22
|
-
super('
|
|
22
|
+
super('wallet file or private key is required');
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.NoWalletProvidedError = NoWalletProvidedError;
|
package/lib/cjs/cli/options.js
CHANGED
|
@@ -51,11 +51,7 @@ exports.optionMap = {
|
|
|
51
51
|
},
|
|
52
52
|
walletFile: {
|
|
53
53
|
alias: '-w, --wallet-file <filePath>',
|
|
54
|
-
description: 'Wallet file to use with the action. Formats accepted: JWK.json,
|
|
55
|
-
},
|
|
56
|
-
mnemonic: {
|
|
57
|
-
alias: '-m, --mnemonic <phrase>',
|
|
58
|
-
description: 'Mnemonic to use with the action',
|
|
54
|
+
description: 'Wallet file to use with the action. Formats accepted: JWK.json, ETH private key as a string, or SOL Secret Key as a Uint8Array',
|
|
59
55
|
},
|
|
60
56
|
privateKey: {
|
|
61
57
|
alias: '-p, --private-key <key>',
|
|
@@ -286,11 +282,7 @@ exports.optionMap = {
|
|
|
286
282
|
description: 'Opaque pagination cursor from a prior payment-history response',
|
|
287
283
|
},
|
|
288
284
|
};
|
|
289
|
-
exports.walletOptions = [
|
|
290
|
-
exports.optionMap.walletFile,
|
|
291
|
-
exports.optionMap.mnemonic,
|
|
292
|
-
exports.optionMap.privateKey,
|
|
293
|
-
];
|
|
285
|
+
exports.walletOptions = [exports.optionMap.walletFile, exports.optionMap.privateKey];
|
|
294
286
|
exports.globalOptions = [
|
|
295
287
|
exports.optionMap.dev,
|
|
296
288
|
exports.optionMap.local,
|
package/lib/cjs/cli/utils.js
CHANGED
|
@@ -68,7 +68,7 @@ function tokenFromOptions(options) {
|
|
|
68
68
|
throw new Error('Token type required');
|
|
69
69
|
}
|
|
70
70
|
if (!(0, index_js_1.isTokenType)(token)) {
|
|
71
|
-
throw new Error(
|
|
71
|
+
throw new Error(`Invalid token type ${token}. Must be one of ${index_js_1.tokenTypes.join(', ')}`);
|
|
72
72
|
}
|
|
73
73
|
return token;
|
|
74
74
|
}
|
|
@@ -112,17 +112,8 @@ async function optionalPrivateKeyFromOptions(options) {
|
|
|
112
112
|
throw error;
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
async function privateKeyFromOptions({
|
|
116
|
-
if (
|
|
117
|
-
if (token === 'kyve') {
|
|
118
|
-
return (0, index_js_1.privateKeyFromKyveMnemonic)(mnemonic);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
// TODO: Implement other token types mnemonic to wallet
|
|
122
|
-
throw new Error('mnemonic provided but this token type mnemonic to wallet is not supported');
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else if (walletFile !== undefined) {
|
|
115
|
+
async function privateKeyFromOptions({ privateKey, walletFile, token, }) {
|
|
116
|
+
if (walletFile !== undefined) {
|
|
126
117
|
const wallet = JSON.parse((0, fs_1.readFileSync)(walletFile, 'utf-8'));
|
|
127
118
|
return token === 'solana' || token === 'ario'
|
|
128
119
|
? bs58_1.default.encode(wallet)
|
|
@@ -131,7 +122,7 @@ async function privateKeyFromOptions({ mnemonic, privateKey, walletFile, token,
|
|
|
131
122
|
else if (privateKey !== undefined) {
|
|
132
123
|
return privateKey;
|
|
133
124
|
}
|
|
134
|
-
// TODO: Get TURBO_WALLET_FILE,
|
|
125
|
+
// TODO: Get TURBO_WALLET_FILE, TURBO_PRIVATE_KEY or similar from ENV variables
|
|
135
126
|
// TODO: Add prompts for selecting wallet type and secure input
|
|
136
127
|
throw new errors_js_1.NoWalletProvidedError();
|
|
137
128
|
}
|
|
@@ -55,7 +55,7 @@ function resolveOwnerAddress(owner) {
|
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* What `getPublicKey()` returns across the supported signers: ed25519 for
|
|
58
|
-
* Solana and ario, uncompressed secp256k1 for Ethereum, Base
|
|
58
|
+
* Solana and ario, uncompressed secp256k1 for Ethereum, Base and Polygon,
|
|
59
59
|
* and a 4096 bit RSA modulus for Arweave.
|
|
60
60
|
*
|
|
61
61
|
* A 32 byte value declared as a `publicKey` is still taken at its word, since
|
package/lib/cjs/common/signer.js
CHANGED
|
@@ -20,14 +20,11 @@ exports.makeX402Signer = makeX402Signer;
|
|
|
20
20
|
* See the License for the specific language governing permissions and
|
|
21
21
|
* limitations under the License.
|
|
22
22
|
*/
|
|
23
|
-
const amino_1 = require("@cosmjs/amino");
|
|
24
|
-
const crypto_1 = require("@cosmjs/crypto");
|
|
25
|
-
const encoding_1 = require("@cosmjs/encoding");
|
|
26
23
|
const arbundles_1 = require("@dha-team/arbundles");
|
|
27
24
|
const web3_js_1 = require("@solana/web3.js");
|
|
28
25
|
const bignumber_js_1 = require("bignumber.js");
|
|
29
26
|
const bs58_1 = __importDefault(require("bs58"));
|
|
30
|
-
const
|
|
27
|
+
const crypto_1 = require("crypto");
|
|
31
28
|
const ethers_1 = require("ethers");
|
|
32
29
|
const ethers_2 = require("ethers");
|
|
33
30
|
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
@@ -61,11 +58,6 @@ class TurboDataItemAbstractSigner {
|
|
|
61
58
|
case 'base-usdc':
|
|
62
59
|
case 'polygon-usdc':
|
|
63
60
|
return (0, ethers_2.computeAddress)(ethers_2.SigningKey.computePublicKey((0, base64_js_1.fromB64Url)(owner)));
|
|
64
|
-
case 'kyve':
|
|
65
|
-
return (0, amino_1.pubkeyToAddress)({
|
|
66
|
-
type: 'tendermint/PubKeySecp256k1',
|
|
67
|
-
value: (0, encoding_1.toBase64)(crypto_1.Secp256k1.compressPubkey(Uint8Array.from((0, base64_js_1.fromB64Url)(owner)))),
|
|
68
|
-
}, 'kyve');
|
|
69
61
|
case 'ario':
|
|
70
62
|
// ARIO is an SPL token, so an `ario` client created from a private key
|
|
71
63
|
// signs with a Solana key. The payment service bills a Solana signature
|
|
@@ -85,7 +77,7 @@ class TurboDataItemAbstractSigner {
|
|
|
85
77
|
async generateSignedRequestHeaders(
|
|
86
78
|
// Callers may supply the nonce (e.g. a UUID required by some routes); the
|
|
87
79
|
// nonce round-trips to the service in `x-nonce` unchanged.
|
|
88
|
-
nonce = (0,
|
|
80
|
+
nonce = (0, crypto_1.randomBytes)(16).toString('hex'),
|
|
89
81
|
// Optional ACTION-BINDING data prepended to the nonce for SIGNING only (not
|
|
90
82
|
// sent): the service reconstructs the same string from the request and
|
|
91
83
|
// verifies the signature over `additionalData + nonce`. This binds the
|
|
@@ -21,7 +21,6 @@ const ario_js_1 = require("./ario.js");
|
|
|
21
21
|
const arweave_js_1 = require("./arweave.js");
|
|
22
22
|
const baseEth_js_1 = require("./baseEth.js");
|
|
23
23
|
const ethereum_js_1 = require("./ethereum.js");
|
|
24
|
-
const kyve_js_1 = require("./kyve.js");
|
|
25
24
|
const polygon_js_1 = require("./polygon.js");
|
|
26
25
|
const solana_js_1 = require("./solana.js");
|
|
27
26
|
const usdc_js_1 = require("./usdc.js");
|
|
@@ -31,7 +30,6 @@ exports.defaultTokenMap = {
|
|
|
31
30
|
solana: (config) => new solana_js_1.SolanaToken(config),
|
|
32
31
|
ethereum: (config) => new ethereum_js_1.EthereumToken(config),
|
|
33
32
|
'base-eth': (config) => new baseEth_js_1.BaseEthToken(config),
|
|
34
|
-
kyve: (config) => new kyve_js_1.KyveToken(config),
|
|
35
33
|
matic: (config) => new polygon_js_1.PolygonToken(config),
|
|
36
34
|
pol: (config) => new polygon_js_1.PolygonToken(config),
|
|
37
35
|
usdc: (config) => new usdc_js_1.USDCToken({ network: 'ethereum', ...config }),
|
|
@@ -47,7 +45,6 @@ exports.exponentMap = {
|
|
|
47
45
|
solana: 9,
|
|
48
46
|
ethereum: ethExponent,
|
|
49
47
|
'base-eth': ethExponent,
|
|
50
|
-
kyve: 6,
|
|
51
48
|
matic: ethExponent,
|
|
52
49
|
pol: ethExponent,
|
|
53
50
|
usdc: usdcExponent,
|
|
@@ -60,7 +57,6 @@ exports.tokenToBaseMap = {
|
|
|
60
57
|
solana: (a) => (0, solana_js_1.SOLToTokenAmount)(a),
|
|
61
58
|
ethereum: (a) => (0, ethereum_js_1.ETHToTokenAmount)(a),
|
|
62
59
|
'base-eth': (a) => (0, ethereum_js_1.ETHToTokenAmount)(a),
|
|
63
|
-
kyve: (a) => (0, kyve_js_1.KYVEToTokenAmount)(a),
|
|
64
60
|
matic: (a) => (0, polygon_js_1.POLToTokenAmount)(a),
|
|
65
61
|
pol: (a) => (0, polygon_js_1.POLToTokenAmount)(a),
|
|
66
62
|
usdc: (a) => (0, usdc_js_1.USDCToTokenAmount)(a),
|
|
@@ -76,4 +72,3 @@ __exportStar(require("./solana.js"), exports);
|
|
|
76
72
|
__exportStar(require("./ethereum.js"), exports);
|
|
77
73
|
__exportStar(require("./baseEth.js"), exports);
|
|
78
74
|
__exportStar(require("./polygon.js"), exports);
|
|
79
|
-
__exportStar(require("./kyve.js"), exports);
|
package/lib/cjs/types.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.arNSFiatPurchaseMethods = exports.arNSActions = exports.arNSPurchaseIntents = exports.validChunkingModes = exports.isJWK = exports.isWebUploadFolderParams = exports.isNodeUploadFolderParams = exports.multipartFinalizedStatus = exports.multipartFailedStatus = exports.multipartPendingStatus = exports.X402Funding = exports.OnDemandFunding = exports.ExistingBalanceFunding = exports.supportedEvmSignerTokens = exports.tokenTypes = exports.fiatCurrencyTypes = void 0;
|
|
4
4
|
exports.isCurrency = isCurrency;
|
|
5
|
-
exports.isKyvePrivateKey = isKyvePrivateKey;
|
|
6
5
|
exports.isEthPrivateKey = isEthPrivateKey;
|
|
7
6
|
exports.isSolanaWalletAdapter = isSolanaWalletAdapter;
|
|
8
7
|
exports.isEthereumWalletAdapter = isEthereumWalletAdapter;
|
|
@@ -27,7 +26,6 @@ exports.tokenTypes = [
|
|
|
27
26
|
'ario',
|
|
28
27
|
'solana',
|
|
29
28
|
'ethereum',
|
|
30
|
-
'kyve',
|
|
31
29
|
'matic',
|
|
32
30
|
'pol',
|
|
33
31
|
'base-eth',
|
|
@@ -86,12 +84,6 @@ const isNodeUploadFolderParams = (p) => p.folderPath !== undefined;
|
|
|
86
84
|
exports.isNodeUploadFolderParams = isNodeUploadFolderParams;
|
|
87
85
|
const isWebUploadFolderParams = (p) => p.files !== undefined;
|
|
88
86
|
exports.isWebUploadFolderParams = isWebUploadFolderParams;
|
|
89
|
-
function isKyvePrivateKey(wallet) {
|
|
90
|
-
if (typeof wallet !== 'string')
|
|
91
|
-
return false;
|
|
92
|
-
// TODO: Hexadecimal regex
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
87
|
function isEthPrivateKey(wallet) {
|
|
96
88
|
if (typeof wallet !== 'string')
|
|
97
89
|
return false;
|
package/lib/cjs/utils/common.js
CHANGED
|
@@ -4,13 +4,10 @@ exports.defaultProdGatewayUrls = exports.tokenToDevGatewayMap = void 0;
|
|
|
4
4
|
exports.sleep = sleep;
|
|
5
5
|
exports.isWeb = isWeb;
|
|
6
6
|
exports.createTurboSigner = createTurboSigner;
|
|
7
|
-
exports.signerFromKyvePrivateKey = signerFromKyvePrivateKey;
|
|
8
|
-
exports.signerFromKyveMnemonic = signerFromKyveMnemonic;
|
|
9
7
|
exports.isBlob = isBlob;
|
|
10
8
|
exports.isValidArweaveBase64URL = isValidArweaveBase64URL;
|
|
11
9
|
exports.isValidSolanaAddress = isValidSolanaAddress;
|
|
12
10
|
exports.isValidECDSAAddress = isValidECDSAAddress;
|
|
13
|
-
exports.isValidKyveAddress = isValidKyveAddress;
|
|
14
11
|
exports.isValidUserAddress = isValidUserAddress;
|
|
15
12
|
exports.isAnyValidUserAddress = isAnyValidUserAddress;
|
|
16
13
|
/**
|
|
@@ -28,9 +25,6 @@ exports.isAnyValidUserAddress = isAnyValidUserAddress;
|
|
|
28
25
|
* See the License for the specific language governing permissions and
|
|
29
26
|
* limitations under the License.
|
|
30
27
|
*/
|
|
31
|
-
const amino_1 = require("@cosmjs/amino");
|
|
32
|
-
const crypto_1 = require("@cosmjs/crypto");
|
|
33
|
-
const encoding_1 = require("@cosmjs/encoding");
|
|
34
28
|
const arbundles_1 = require("@dha-team/arbundles");
|
|
35
29
|
const web3_js_1 = require("@solana/web3.js");
|
|
36
30
|
const ethers_1 = require("ethers");
|
|
@@ -51,7 +45,6 @@ exports.tokenToDevGatewayMap = {
|
|
|
51
45
|
solana: 'https://api.devnet.solana.com',
|
|
52
46
|
ethereum: ethTestnetRpc,
|
|
53
47
|
'base-eth': baseTestnetRpc,
|
|
54
|
-
kyve: 'https://api.korellia.kyve.network',
|
|
55
48
|
matic: polygonTestnetRpc,
|
|
56
49
|
pol: polygonTestnetRpc,
|
|
57
50
|
usdc: ethTestnetRpc,
|
|
@@ -64,7 +57,6 @@ exports.defaultProdGatewayUrls = {
|
|
|
64
57
|
solana: 'https://api.mainnet-beta.solana.com',
|
|
65
58
|
ethereum: 'https://cloudflare-eth.com/',
|
|
66
59
|
'base-eth': baseMainnetRpc,
|
|
67
|
-
kyve: 'https://api.kyve.network/',
|
|
68
60
|
matic: 'https://polygon-rpc.com/',
|
|
69
61
|
pol: 'https://polygon-rpc.com/',
|
|
70
62
|
usdc: 'https://cloudflare-eth.com/',
|
|
@@ -103,11 +95,6 @@ function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientPro
|
|
|
103
95
|
throw new Error('A valid Ethereum private key must be provided for EthereumSigner.');
|
|
104
96
|
}
|
|
105
97
|
return new arbundles_1.EthereumSigner(clientProvidedPrivateKey);
|
|
106
|
-
case 'kyve':
|
|
107
|
-
if (!(0, types_js_1.isKyvePrivateKey)(clientProvidedPrivateKey)) {
|
|
108
|
-
throw new Error('A valid Kyve private key must be provided for KyveSigner.');
|
|
109
|
-
}
|
|
110
|
-
return signerFromKyvePrivateKey(clientProvidedPrivateKey);
|
|
111
98
|
case 'arweave':
|
|
112
99
|
if (!(0, types_js_1.isJWK)(clientProvidedPrivateKey)) {
|
|
113
100
|
throw new Error('A JWK must be provided for ArweaveSigner.');
|
|
@@ -115,17 +102,6 @@ function createTurboSigner({ signer: clientProvidedSigner, privateKey: clientPro
|
|
|
115
102
|
return new arbundles_1.ArweaveSigner(clientProvidedPrivateKey);
|
|
116
103
|
}
|
|
117
104
|
}
|
|
118
|
-
function signerFromKyvePrivateKey(privateKey) {
|
|
119
|
-
// TODO: Use KyveSigner when implemented for on chain native address support
|
|
120
|
-
return new arbundles_1.EthereumSigner(privateKey);
|
|
121
|
-
}
|
|
122
|
-
async function signerFromKyveMnemonic(mnemonic) {
|
|
123
|
-
const kyveWallet = await amino_1.Secp256k1HdWallet.fromMnemonic(mnemonic, {
|
|
124
|
-
prefix: 'kyve',
|
|
125
|
-
});
|
|
126
|
-
const privateKey = (0, encoding_1.toHex)(crypto_1.Slip10.derivePath(crypto_1.Slip10Curve.Secp256k1, kyveWallet['seed'], (0, amino_1.makeCosmoshubPath)(0)).privkey);
|
|
127
|
-
return signerFromKyvePrivateKey(privateKey);
|
|
128
|
-
}
|
|
129
105
|
function isBlob(val) {
|
|
130
106
|
return typeof Blob !== 'undefined' && val instanceof Blob;
|
|
131
107
|
}
|
|
@@ -146,10 +122,6 @@ function isValidECDSAAddress(address) {
|
|
|
146
122
|
const ethAddressRegex = new RegExp('^0x[a-fA-F0-9]{40}$');
|
|
147
123
|
return ethAddressRegex.test(address);
|
|
148
124
|
}
|
|
149
|
-
function isValidKyveAddress(address) {
|
|
150
|
-
const kyveAddressRegex = new RegExp('^kyve[a-zA-Z0-9]{39}$');
|
|
151
|
-
return kyveAddressRegex.test(address);
|
|
152
|
-
}
|
|
153
125
|
function isValidUserAddress(address, type) {
|
|
154
126
|
switch (type) {
|
|
155
127
|
case 'arweave':
|
|
@@ -165,8 +137,6 @@ function isValidUserAddress(address, type) {
|
|
|
165
137
|
case 'usdc':
|
|
166
138
|
case 'polygon-usdc':
|
|
167
139
|
return isValidECDSAAddress(address);
|
|
168
|
-
case 'kyve':
|
|
169
|
-
return isValidKyveAddress(address);
|
|
170
140
|
}
|
|
171
141
|
}
|
|
172
142
|
function isAnyValidUserAddress(address) {
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/cli/errors.js
CHANGED
package/lib/esm/cli/options.js
CHANGED
|
@@ -48,11 +48,7 @@ export const optionMap = {
|
|
|
48
48
|
},
|
|
49
49
|
walletFile: {
|
|
50
50
|
alias: '-w, --wallet-file <filePath>',
|
|
51
|
-
description: 'Wallet file to use with the action. Formats accepted: JWK.json,
|
|
52
|
-
},
|
|
53
|
-
mnemonic: {
|
|
54
|
-
alias: '-m, --mnemonic <phrase>',
|
|
55
|
-
description: 'Mnemonic to use with the action',
|
|
51
|
+
description: 'Wallet file to use with the action. Formats accepted: JWK.json, ETH private key as a string, or SOL Secret Key as a Uint8Array',
|
|
56
52
|
},
|
|
57
53
|
privateKey: {
|
|
58
54
|
alias: '-p, --private-key <key>',
|
|
@@ -283,11 +279,7 @@ export const optionMap = {
|
|
|
283
279
|
description: 'Opaque pagination cursor from a prior payment-history response',
|
|
284
280
|
},
|
|
285
281
|
};
|
|
286
|
-
export const walletOptions = [
|
|
287
|
-
optionMap.walletFile,
|
|
288
|
-
optionMap.mnemonic,
|
|
289
|
-
optionMap.privateKey,
|
|
290
|
-
];
|
|
282
|
+
export const walletOptions = [optionMap.walletFile, optionMap.privateKey];
|
|
291
283
|
export const globalOptions = [
|
|
292
284
|
optionMap.dev,
|
|
293
285
|
optionMap.local,
|
package/lib/esm/cli/utils.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import bs58 from 'bs58';
|
|
17
17
|
import { readFileSync, statSync } from 'fs';
|
|
18
|
-
import { ExistingBalanceFunding, OnDemandFunding, TurboFactory, X402Funding, defaultTurboConfiguration, developmentTurboConfiguration, fiatCurrencyTypes, isCurrency, isTokenType,
|
|
18
|
+
import { ExistingBalanceFunding, OnDemandFunding, TurboFactory, X402Funding, defaultTurboConfiguration, developmentTurboConfiguration, fiatCurrencyTypes, isCurrency, isTokenType, tokenToBaseMap, tokenTypes, } from '../node/index.js';
|
|
19
19
|
import { tokenToDevGatewayMap } from '../utils/common.js';
|
|
20
20
|
import { NoWalletProvidedError } from './errors.js';
|
|
21
21
|
export function exitWithErrorLog(error) {
|
|
@@ -44,7 +44,7 @@ export function tokenFromOptions(options) {
|
|
|
44
44
|
throw new Error('Token type required');
|
|
45
45
|
}
|
|
46
46
|
if (!isTokenType(token)) {
|
|
47
|
-
throw new Error(
|
|
47
|
+
throw new Error(`Invalid token type ${token}. Must be one of ${tokenTypes.join(', ')}`);
|
|
48
48
|
}
|
|
49
49
|
return token;
|
|
50
50
|
}
|
|
@@ -88,17 +88,8 @@ export async function optionalPrivateKeyFromOptions(options) {
|
|
|
88
88
|
throw error;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
export async function privateKeyFromOptions({
|
|
92
|
-
if (
|
|
93
|
-
if (token === 'kyve') {
|
|
94
|
-
return privateKeyFromKyveMnemonic(mnemonic);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
// TODO: Implement other token types mnemonic to wallet
|
|
98
|
-
throw new Error('mnemonic provided but this token type mnemonic to wallet is not supported');
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else if (walletFile !== undefined) {
|
|
91
|
+
export async function privateKeyFromOptions({ privateKey, walletFile, token, }) {
|
|
92
|
+
if (walletFile !== undefined) {
|
|
102
93
|
const wallet = JSON.parse(readFileSync(walletFile, 'utf-8'));
|
|
103
94
|
return token === 'solana' || token === 'ario'
|
|
104
95
|
? bs58.encode(wallet)
|
|
@@ -107,7 +98,7 @@ export async function privateKeyFromOptions({ mnemonic, privateKey, walletFile,
|
|
|
107
98
|
else if (privateKey !== undefined) {
|
|
108
99
|
return privateKey;
|
|
109
100
|
}
|
|
110
|
-
// TODO: Get TURBO_WALLET_FILE,
|
|
101
|
+
// TODO: Get TURBO_WALLET_FILE, TURBO_PRIVATE_KEY or similar from ENV variables
|
|
111
102
|
// TODO: Add prompts for selecting wallet type and secure input
|
|
112
103
|
throw new NoWalletProvidedError();
|
|
113
104
|
}
|
|
@@ -50,7 +50,7 @@ function resolveOwnerAddress(owner) {
|
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* What `getPublicKey()` returns across the supported signers: ed25519 for
|
|
53
|
-
* Solana and ario, uncompressed secp256k1 for Ethereum, Base
|
|
53
|
+
* Solana and ario, uncompressed secp256k1 for Ethereum, Base and Polygon,
|
|
54
54
|
* and a 4096 bit RSA modulus for Arweave.
|
|
55
55
|
*
|
|
56
56
|
* A 32 byte value declared as a `publicKey` is still taken at its word, since
|
package/lib/esm/common/signer.js
CHANGED
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { pubkeyToAddress } from '@cosmjs/amino';
|
|
17
|
-
import { Secp256k1 } from '@cosmjs/crypto';
|
|
18
|
-
import { toBase64 } from '@cosmjs/encoding';
|
|
19
16
|
import { EthereumSigner, HexSolanaSigner, SignatureConfig, } from '@dha-team/arbundles';
|
|
20
17
|
import { Connection, PublicKey, SystemProgram, Transaction, TransactionInstruction, } from '@solana/web3.js';
|
|
21
18
|
import { BigNumber } from 'bignumber.js';
|
|
@@ -54,11 +51,6 @@ export class TurboDataItemAbstractSigner {
|
|
|
54
51
|
case 'base-usdc':
|
|
55
52
|
case 'polygon-usdc':
|
|
56
53
|
return computeAddress(SigningKey.computePublicKey(fromB64Url(owner)));
|
|
57
|
-
case 'kyve':
|
|
58
|
-
return pubkeyToAddress({
|
|
59
|
-
type: 'tendermint/PubKeySecp256k1',
|
|
60
|
-
value: toBase64(Secp256k1.compressPubkey(Uint8Array.from(fromB64Url(owner)))),
|
|
61
|
-
}, 'kyve');
|
|
62
54
|
case 'ario':
|
|
63
55
|
// ARIO is an SPL token, so an `ario` client created from a private key
|
|
64
56
|
// signs with a Solana key. The payment service bills a Solana signature
|
|
@@ -3,7 +3,6 @@ import { ARIOToTokenAmount, ARIOToken } from './ario.js';
|
|
|
3
3
|
import { ARToTokenAmount, ArweaveToken } from './arweave.js';
|
|
4
4
|
import { BaseEthToken } from './baseEth.js';
|
|
5
5
|
import { ETHToTokenAmount, EthereumToken } from './ethereum.js';
|
|
6
|
-
import { KYVEToTokenAmount, KyveToken } from './kyve.js';
|
|
7
6
|
import { POLToTokenAmount, PolygonToken } from './polygon.js';
|
|
8
7
|
import { SOLToTokenAmount, SolanaToken } from './solana.js';
|
|
9
8
|
import { USDCToTokenAmount, USDCToken } from './usdc.js';
|
|
@@ -13,7 +12,6 @@ export const defaultTokenMap = {
|
|
|
13
12
|
solana: (config) => new SolanaToken(config),
|
|
14
13
|
ethereum: (config) => new EthereumToken(config),
|
|
15
14
|
'base-eth': (config) => new BaseEthToken(config),
|
|
16
|
-
kyve: (config) => new KyveToken(config),
|
|
17
15
|
matic: (config) => new PolygonToken(config),
|
|
18
16
|
pol: (config) => new PolygonToken(config),
|
|
19
17
|
usdc: (config) => new USDCToken({ network: 'ethereum', ...config }),
|
|
@@ -29,7 +27,6 @@ export const exponentMap = {
|
|
|
29
27
|
solana: 9,
|
|
30
28
|
ethereum: ethExponent,
|
|
31
29
|
'base-eth': ethExponent,
|
|
32
|
-
kyve: 6,
|
|
33
30
|
matic: ethExponent,
|
|
34
31
|
pol: ethExponent,
|
|
35
32
|
usdc: usdcExponent,
|
|
@@ -42,7 +39,6 @@ export const tokenToBaseMap = {
|
|
|
42
39
|
solana: (a) => SOLToTokenAmount(a),
|
|
43
40
|
ethereum: (a) => ETHToTokenAmount(a),
|
|
44
41
|
'base-eth': (a) => ETHToTokenAmount(a),
|
|
45
|
-
kyve: (a) => KYVEToTokenAmount(a),
|
|
46
42
|
matic: (a) => POLToTokenAmount(a),
|
|
47
43
|
pol: (a) => POLToTokenAmount(a),
|
|
48
44
|
usdc: (a) => USDCToTokenAmount(a),
|
|
@@ -58,4 +54,3 @@ export * from './solana.js';
|
|
|
58
54
|
export * from './ethereum.js';
|
|
59
55
|
export * from './baseEth.js';
|
|
60
56
|
export * from './polygon.js';
|
|
61
|
-
export * from './kyve.js';
|
package/lib/esm/types.js
CHANGED
|
@@ -19,7 +19,6 @@ export const tokenTypes = [
|
|
|
19
19
|
'ario',
|
|
20
20
|
'solana',
|
|
21
21
|
'ethereum',
|
|
22
|
-
'kyve',
|
|
23
22
|
'matic',
|
|
24
23
|
'pol',
|
|
25
24
|
'base-eth',
|
|
@@ -73,12 +72,6 @@ export const multipartFailedStatus = [
|
|
|
73
72
|
export const multipartFinalizedStatus = ['FINALIZED'];
|
|
74
73
|
export const isNodeUploadFolderParams = (p) => p.folderPath !== undefined;
|
|
75
74
|
export const isWebUploadFolderParams = (p) => p.files !== undefined;
|
|
76
|
-
export function isKyvePrivateKey(wallet) {
|
|
77
|
-
if (typeof wallet !== 'string')
|
|
78
|
-
return false;
|
|
79
|
-
// TODO: Hexadecimal regex
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
75
|
export function isEthPrivateKey(wallet) {
|
|
83
76
|
if (typeof wallet !== 'string')
|
|
84
77
|
return false;
|
package/lib/esm/utils/common.js
CHANGED
|
@@ -13,13 +13,10 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { Secp256k1HdWallet, makeCosmoshubPath } from '@cosmjs/amino';
|
|
17
|
-
import { Slip10, Slip10Curve } from '@cosmjs/crypto';
|
|
18
|
-
import { toHex } from '@cosmjs/encoding';
|
|
19
16
|
import { ArweaveSigner, EthereumSigner, HexSolanaSigner, InjectedEthereumSigner, } from '@dha-team/arbundles';
|
|
20
17
|
import { PublicKey } from '@solana/web3.js';
|
|
21
18
|
import { SigningKey, getBytes, hashMessage } from 'ethers';
|
|
22
|
-
import { isEthPrivateKey, isJWK,
|
|
19
|
+
import { isEthPrivateKey, isJWK, tokenTypes, } from '../types.js';
|
|
23
20
|
export function sleep(ms) {
|
|
24
21
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
25
22
|
}
|
|
@@ -36,7 +33,6 @@ export const tokenToDevGatewayMap = {
|
|
|
36
33
|
solana: 'https://api.devnet.solana.com',
|
|
37
34
|
ethereum: ethTestnetRpc,
|
|
38
35
|
'base-eth': baseTestnetRpc,
|
|
39
|
-
kyve: 'https://api.korellia.kyve.network',
|
|
40
36
|
matic: polygonTestnetRpc,
|
|
41
37
|
pol: polygonTestnetRpc,
|
|
42
38
|
usdc: ethTestnetRpc,
|
|
@@ -49,7 +45,6 @@ export const defaultProdGatewayUrls = {
|
|
|
49
45
|
solana: 'https://api.mainnet-beta.solana.com',
|
|
50
46
|
ethereum: 'https://cloudflare-eth.com/',
|
|
51
47
|
'base-eth': baseMainnetRpc,
|
|
52
|
-
kyve: 'https://api.kyve.network/',
|
|
53
48
|
matic: 'https://polygon-rpc.com/',
|
|
54
49
|
pol: 'https://polygon-rpc.com/',
|
|
55
50
|
usdc: 'https://cloudflare-eth.com/',
|
|
@@ -88,11 +83,6 @@ export function createTurboSigner({ signer: clientProvidedSigner, privateKey: cl
|
|
|
88
83
|
throw new Error('A valid Ethereum private key must be provided for EthereumSigner.');
|
|
89
84
|
}
|
|
90
85
|
return new EthereumSigner(clientProvidedPrivateKey);
|
|
91
|
-
case 'kyve':
|
|
92
|
-
if (!isKyvePrivateKey(clientProvidedPrivateKey)) {
|
|
93
|
-
throw new Error('A valid Kyve private key must be provided for KyveSigner.');
|
|
94
|
-
}
|
|
95
|
-
return signerFromKyvePrivateKey(clientProvidedPrivateKey);
|
|
96
86
|
case 'arweave':
|
|
97
87
|
if (!isJWK(clientProvidedPrivateKey)) {
|
|
98
88
|
throw new Error('A JWK must be provided for ArweaveSigner.');
|
|
@@ -100,17 +90,6 @@ export function createTurboSigner({ signer: clientProvidedSigner, privateKey: cl
|
|
|
100
90
|
return new ArweaveSigner(clientProvidedPrivateKey);
|
|
101
91
|
}
|
|
102
92
|
}
|
|
103
|
-
export function signerFromKyvePrivateKey(privateKey) {
|
|
104
|
-
// TODO: Use KyveSigner when implemented for on chain native address support
|
|
105
|
-
return new EthereumSigner(privateKey);
|
|
106
|
-
}
|
|
107
|
-
export async function signerFromKyveMnemonic(mnemonic) {
|
|
108
|
-
const kyveWallet = await Secp256k1HdWallet.fromMnemonic(mnemonic, {
|
|
109
|
-
prefix: 'kyve',
|
|
110
|
-
});
|
|
111
|
-
const privateKey = toHex(Slip10.derivePath(Slip10Curve.Secp256k1, kyveWallet['seed'], makeCosmoshubPath(0)).privkey);
|
|
112
|
-
return signerFromKyvePrivateKey(privateKey);
|
|
113
|
-
}
|
|
114
93
|
export function isBlob(val) {
|
|
115
94
|
return typeof Blob !== 'undefined' && val instanceof Blob;
|
|
116
95
|
}
|
|
@@ -131,10 +110,6 @@ export function isValidECDSAAddress(address) {
|
|
|
131
110
|
const ethAddressRegex = new RegExp('^0x[a-fA-F0-9]{40}$');
|
|
132
111
|
return ethAddressRegex.test(address);
|
|
133
112
|
}
|
|
134
|
-
export function isValidKyveAddress(address) {
|
|
135
|
-
const kyveAddressRegex = new RegExp('^kyve[a-zA-Z0-9]{39}$');
|
|
136
|
-
return kyveAddressRegex.test(address);
|
|
137
|
-
}
|
|
138
113
|
export function isValidUserAddress(address, type) {
|
|
139
114
|
switch (type) {
|
|
140
115
|
case 'arweave':
|
|
@@ -150,8 +125,6 @@ export function isValidUserAddress(address, type) {
|
|
|
150
125
|
case 'usdc':
|
|
151
126
|
case 'polygon-usdc':
|
|
152
127
|
return isValidECDSAAddress(address);
|
|
153
|
-
case 'kyve':
|
|
154
|
-
return isValidKyveAddress(address);
|
|
155
128
|
}
|
|
156
129
|
}
|
|
157
130
|
export function isAnyValidUserAddress(address) {
|
package/lib/esm/version.js
CHANGED