@rozoai/intent-common 0.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/LICENSE +26 -0
- package/dist/assert.d.ts +5 -0
- package/dist/assert.js +31 -0
- package/dist/assert.js.map +1 -0
- package/dist/chain.d.ts +40 -0
- package/dist/chain.js +168 -0
- package/dist/chain.js.map +1 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.js +17 -0
- package/dist/debug.js.map +1 -0
- package/dist/format.d.ts +13 -0
- package/dist/format.js +25 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/primitiveTypes.d.ts +8 -0
- package/dist/primitiveTypes.js +18 -0
- package/dist/primitiveTypes.js.map +1 -0
- package/dist/retryBackoff.d.ts +5 -0
- package/dist/retryBackoff.js +28 -0
- package/dist/retryBackoff.js.map +1 -0
- package/dist/rozoPay.d.ts +450 -0
- package/dist/rozoPay.js +250 -0
- package/dist/rozoPay.js.map +1 -0
- package/dist/token.d.ts +128 -0
- package/dist/token.js +852 -0
- package/dist/token.js.map +1 -0
- package/dist/try.d.ts +3 -0
- package/dist/try.js +31 -0
- package/dist/try.js.map +1 -0
- package/package.json +35 -0
- package/src/assert.ts +29 -0
- package/src/chain.ts +182 -0
- package/src/debug.ts +14 -0
- package/src/format.ts +21 -0
- package/src/index.ts +9 -0
- package/src/primitiveTypes.ts +25 -0
- package/src/retryBackoff.ts +30 -0
- package/src/rozoPay.ts +571 -0
- package/src/token.ts +1020 -0
- package/src/try.ts +25 -0
- package/tsconfig.json +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, Daimo, Inc.
|
|
4
|
+
Copyright (c) 2022, LFE, Inc.
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
11
|
+
list of conditions and the following disclaimer.
|
|
12
|
+
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/dist/assert.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function assert(condition: boolean, ...args: any[]): asserts condition;
|
|
2
|
+
export declare function assertNotNull<T>(value: T | null | undefined, ...args: any[]): T;
|
|
3
|
+
export declare function assertEqual<T>(a: T, b: T, ...args: any[]): void;
|
|
4
|
+
/** Used to compile-time check that switch statements are exhaustive, etc. */
|
|
5
|
+
export declare function assertUnreachable(_: never): never;
|
package/dist/assert.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assert = assert;
|
|
4
|
+
exports.assertNotNull = assertNotNull;
|
|
5
|
+
exports.assertEqual = assertEqual;
|
|
6
|
+
exports.assertUnreachable = assertUnreachable;
|
|
7
|
+
const debug_1 = require("./debug");
|
|
8
|
+
function assert(condition, ...args) {
|
|
9
|
+
if (condition)
|
|
10
|
+
return;
|
|
11
|
+
let msg;
|
|
12
|
+
if (args.length === 1 && typeof args[0] === "function") {
|
|
13
|
+
msg = args[0]();
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
msg = args.map((a) => (0, debug_1.debugJson)(a)).join(", ");
|
|
17
|
+
}
|
|
18
|
+
throw new Error("Assertion failed: " + msg);
|
|
19
|
+
}
|
|
20
|
+
function assertNotNull(value, ...args) {
|
|
21
|
+
assert(value !== null && value !== undefined, ...args);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function assertEqual(a, b, ...args) {
|
|
25
|
+
assert(a === b, ...args);
|
|
26
|
+
}
|
|
27
|
+
/** Used to compile-time check that switch statements are exhaustive, etc. */
|
|
28
|
+
function assertUnreachable(_) {
|
|
29
|
+
throw new Error("Unreachable");
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":";;AAEA,wBASC;AAED,sCAMC;AAED,kCAEC;AAGD,8CAEC;AA5BD,mCAAoC;AAEpC,SAAgB,MAAM,CAAC,SAAkB,EAAE,GAAG,IAAW;IACvD,IAAI,SAAS;QAAE,OAAO;IACtB,IAAI,GAAW,CAAC;IAChB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;QACvD,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,iBAAS,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED,SAAgB,aAAa,CAC3B,KAA2B,EAC3B,GAAG,IAAW;IAEd,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,WAAW,CAAI,CAAI,EAAE,CAAI,EAAE,GAAG,IAAW;IACvD,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,6EAA6E;AAC7E,SAAgB,iBAAiB,CAAC,CAAQ;IACxC,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/chain.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type Chain = {
|
|
2
|
+
type: "evm" | "solana";
|
|
3
|
+
chainId: number;
|
|
4
|
+
name: string;
|
|
5
|
+
cctpDomain: number | null;
|
|
6
|
+
};
|
|
7
|
+
export declare const arbitrum: Chain;
|
|
8
|
+
export declare const base: Chain;
|
|
9
|
+
export declare const bsc: Chain;
|
|
10
|
+
export declare const celo: Chain;
|
|
11
|
+
export declare const ethereum: Chain;
|
|
12
|
+
export declare const linea: Chain;
|
|
13
|
+
export declare const mantle: Chain;
|
|
14
|
+
export declare const optimism: Chain;
|
|
15
|
+
export declare const polygon: Chain;
|
|
16
|
+
export declare const solana: Chain;
|
|
17
|
+
export declare const worldchain: Chain;
|
|
18
|
+
export declare const supportedChains: Chain[];
|
|
19
|
+
/** Given a chainId, return the chain. */
|
|
20
|
+
export declare function getChainById(chainId: number): Chain;
|
|
21
|
+
/** Returns the chain name for the given chainId. */
|
|
22
|
+
export declare function getChainName(chainId: number): string;
|
|
23
|
+
/** Returns the CCTP domain for the given chainId. */
|
|
24
|
+
export declare function getCCTPDomain(chainId: number): number | null;
|
|
25
|
+
/** Returns true if the chain is a CCTP v1 chain. */
|
|
26
|
+
export declare function isCCTPV1Chain(chainId: number): boolean;
|
|
27
|
+
/** Returns true if the chain is a CCTP v2 chain. */
|
|
28
|
+
export declare function isCCTPV2Chain(chainId: number): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Get block explorer URL for chain ID
|
|
31
|
+
*/
|
|
32
|
+
export declare function getChainExplorerByChainId(chainId: number): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Get block explorer address URL for chain ID and address.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getChainExplorerAddressUrl(chainId: number, address: string): string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Get block explorer transaction URL for chain ID and transaction hash.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getChainExplorerTxUrl(chainId: number, txHash: string): string | undefined;
|
package/dist/chain.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.supportedChains = exports.worldchain = exports.solana = exports.polygon = exports.optimism = exports.mantle = exports.linea = exports.ethereum = exports.celo = exports.bsc = exports.base = exports.arbitrum = void 0;
|
|
4
|
+
exports.getChainById = getChainById;
|
|
5
|
+
exports.getChainName = getChainName;
|
|
6
|
+
exports.getCCTPDomain = getCCTPDomain;
|
|
7
|
+
exports.isCCTPV1Chain = isCCTPV1Chain;
|
|
8
|
+
exports.isCCTPV2Chain = isCCTPV2Chain;
|
|
9
|
+
exports.getChainExplorerByChainId = getChainExplorerByChainId;
|
|
10
|
+
exports.getChainExplorerAddressUrl = getChainExplorerAddressUrl;
|
|
11
|
+
exports.getChainExplorerTxUrl = getChainExplorerTxUrl;
|
|
12
|
+
exports.arbitrum = {
|
|
13
|
+
type: "evm",
|
|
14
|
+
chainId: 42161,
|
|
15
|
+
name: "Arbitrum",
|
|
16
|
+
cctpDomain: 3,
|
|
17
|
+
};
|
|
18
|
+
exports.base = {
|
|
19
|
+
type: "evm",
|
|
20
|
+
chainId: 8453,
|
|
21
|
+
name: "Base",
|
|
22
|
+
cctpDomain: 6,
|
|
23
|
+
};
|
|
24
|
+
exports.bsc = {
|
|
25
|
+
type: "evm",
|
|
26
|
+
chainId: 56,
|
|
27
|
+
name: "BNB Smart Chain",
|
|
28
|
+
cctpDomain: null,
|
|
29
|
+
};
|
|
30
|
+
exports.celo = {
|
|
31
|
+
type: "evm",
|
|
32
|
+
chainId: 42220,
|
|
33
|
+
name: "Celo",
|
|
34
|
+
cctpDomain: null,
|
|
35
|
+
};
|
|
36
|
+
exports.ethereum = {
|
|
37
|
+
type: "evm",
|
|
38
|
+
chainId: 1,
|
|
39
|
+
name: "Ethereum",
|
|
40
|
+
cctpDomain: 0,
|
|
41
|
+
};
|
|
42
|
+
exports.linea = {
|
|
43
|
+
type: "evm",
|
|
44
|
+
chainId: 59144,
|
|
45
|
+
name: "Linea",
|
|
46
|
+
cctpDomain: 11,
|
|
47
|
+
};
|
|
48
|
+
exports.mantle = {
|
|
49
|
+
type: "evm",
|
|
50
|
+
chainId: 5000,
|
|
51
|
+
name: "Mantle",
|
|
52
|
+
cctpDomain: null,
|
|
53
|
+
};
|
|
54
|
+
exports.optimism = {
|
|
55
|
+
type: "evm",
|
|
56
|
+
chainId: 10,
|
|
57
|
+
name: "Optimism",
|
|
58
|
+
cctpDomain: 2,
|
|
59
|
+
};
|
|
60
|
+
exports.polygon = {
|
|
61
|
+
type: "evm",
|
|
62
|
+
chainId: 137,
|
|
63
|
+
name: "Polygon",
|
|
64
|
+
cctpDomain: 7,
|
|
65
|
+
};
|
|
66
|
+
exports.solana = {
|
|
67
|
+
type: "solana",
|
|
68
|
+
chainId: 501,
|
|
69
|
+
name: "Solana",
|
|
70
|
+
cctpDomain: 5,
|
|
71
|
+
};
|
|
72
|
+
exports.worldchain = {
|
|
73
|
+
type: "evm",
|
|
74
|
+
chainId: 480,
|
|
75
|
+
name: "Worldchain",
|
|
76
|
+
cctpDomain: 14,
|
|
77
|
+
};
|
|
78
|
+
exports.supportedChains = [
|
|
79
|
+
exports.arbitrum,
|
|
80
|
+
exports.base,
|
|
81
|
+
exports.bsc,
|
|
82
|
+
exports.celo,
|
|
83
|
+
exports.ethereum,
|
|
84
|
+
exports.linea,
|
|
85
|
+
exports.mantle,
|
|
86
|
+
exports.optimism,
|
|
87
|
+
exports.polygon,
|
|
88
|
+
exports.solana,
|
|
89
|
+
exports.worldchain,
|
|
90
|
+
];
|
|
91
|
+
// https://developers.circle.com/stablecoins/supported-domains
|
|
92
|
+
const cctpV1Chains = [exports.arbitrum, exports.base, exports.ethereum, exports.optimism, exports.polygon, exports.solana];
|
|
93
|
+
const cctpV2Chains = [exports.arbitrum, exports.base, exports.ethereum, exports.linea, exports.worldchain];
|
|
94
|
+
/** Given a chainId, return the chain. */
|
|
95
|
+
function getChainById(chainId) {
|
|
96
|
+
const ret = exports.supportedChains.find((c) => c.chainId === chainId);
|
|
97
|
+
if (ret == null)
|
|
98
|
+
throw new Error(`Unknown chainId ${chainId}`);
|
|
99
|
+
return ret;
|
|
100
|
+
}
|
|
101
|
+
/** Returns the chain name for the given chainId. */
|
|
102
|
+
function getChainName(chainId) {
|
|
103
|
+
return getChainById(chainId).name;
|
|
104
|
+
}
|
|
105
|
+
/** Returns the CCTP domain for the given chainId. */
|
|
106
|
+
function getCCTPDomain(chainId) {
|
|
107
|
+
return getChainById(chainId).cctpDomain;
|
|
108
|
+
}
|
|
109
|
+
/** Returns true if the chain is a CCTP v1 chain. */
|
|
110
|
+
function isCCTPV1Chain(chainId) {
|
|
111
|
+
return cctpV1Chains.some((c) => c.chainId === chainId);
|
|
112
|
+
}
|
|
113
|
+
/** Returns true if the chain is a CCTP v2 chain. */
|
|
114
|
+
function isCCTPV2Chain(chainId) {
|
|
115
|
+
return cctpV2Chains.some((c) => c.chainId === chainId);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get block explorer URL for chain ID
|
|
119
|
+
*/
|
|
120
|
+
function getChainExplorerByChainId(chainId) {
|
|
121
|
+
switch (chainId) {
|
|
122
|
+
case exports.arbitrum.chainId:
|
|
123
|
+
return "https://arbiscan.io";
|
|
124
|
+
case exports.base.chainId:
|
|
125
|
+
return "https://basescan.org";
|
|
126
|
+
case exports.bsc.chainId:
|
|
127
|
+
return "https://bscscan.com";
|
|
128
|
+
case exports.celo.chainId:
|
|
129
|
+
return "https://celoscan.io";
|
|
130
|
+
case exports.ethereum.chainId:
|
|
131
|
+
return "https://etherscan.io";
|
|
132
|
+
case exports.linea.chainId:
|
|
133
|
+
return "https://lineascan.build";
|
|
134
|
+
case exports.mantle.chainId:
|
|
135
|
+
return "https://mantlescan.xyz";
|
|
136
|
+
case exports.optimism.chainId:
|
|
137
|
+
return "https://optimistic.etherscan.io";
|
|
138
|
+
case exports.polygon.chainId:
|
|
139
|
+
return "https://polygonscan.com";
|
|
140
|
+
case exports.solana.chainId:
|
|
141
|
+
return "https://solscan.io";
|
|
142
|
+
case exports.worldchain.chainId:
|
|
143
|
+
return "https://worldscan.org";
|
|
144
|
+
default:
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get block explorer address URL for chain ID and address.
|
|
150
|
+
*/
|
|
151
|
+
function getChainExplorerAddressUrl(chainId, address) {
|
|
152
|
+
const explorer = getChainExplorerByChainId(chainId);
|
|
153
|
+
if (!explorer) {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
return `${explorer}/address/${address}`;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get block explorer transaction URL for chain ID and transaction hash.
|
|
160
|
+
*/
|
|
161
|
+
function getChainExplorerTxUrl(chainId, txHash) {
|
|
162
|
+
const explorer = getChainExplorerByChainId(chainId);
|
|
163
|
+
if (!explorer) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
return `${explorer}/tx/${txHash}`;
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":";;;AAuGA,oCAIC;AAGD,oCAEC;AAGD,sCAEC;AAGD,sCAEC;AAGD,sCAEC;AAKD,8DA2BC;AAKD,gEAMC;AAKD,sDAMC;AA9KY,QAAA,QAAQ,GAAU;IAC7B,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,CAAC;CACd,CAAC;AAEW,QAAA,IAAI,GAAU;IACzB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,CAAC;CACd,CAAC;AAEW,QAAA,GAAG,GAAU;IACxB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,iBAAiB;IACvB,UAAU,EAAE,IAAI;CACjB,CAAC;AAEW,QAAA,IAAI,GAAU;IACzB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,IAAI;CACjB,CAAC;AAEW,QAAA,QAAQ,GAAU;IAC7B,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,CAAC;CACd,CAAC;AAEW,QAAA,KAAK,GAAU;IAC1B,IAAI,EAA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BAAwB,CAAC;QAClC,KAAK,gBAAQ,CAAC,OAAO;YACnB,OAAO,iCAAiC,CAAC;QAC3C,KAAK,eAAO,CAAC,OAAO;YAClB,OAAO,yBAAyB,CAAC;QACnC,KAAK,cAAM,CAAC,OAAO;YACjB,OAAO,oBAAoB,CAAC;QAC9B,KAAK,kBAAU,CAAC,OAAO;YACrB,OAAO,uBAAuB,CAAC;QACjC;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,0BAA0B,CAAC,OAAe,EAAE,OAAe;IACzE,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,QAAQ,YAAY,OAAO,EAAE,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,OAAe,EAAE,MAAc;IACnE,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,QAAQ,OAAO,MAAM,EAAE,CAAC;AACpC,CAAC"}
|
package/dist/debug.d.ts
ADDED
package/dist/debug.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debugJson = debugJson;
|
|
4
|
+
/** Return compact JSON, 10000 chars max. Never throws. */
|
|
5
|
+
function debugJson(obj) {
|
|
6
|
+
try {
|
|
7
|
+
let serialized = JSON.stringify(obj, (_, value) => typeof value === "bigint" ? value.toString() : value);
|
|
8
|
+
if (typeof serialized !== "string") {
|
|
9
|
+
serialized = "" + obj;
|
|
10
|
+
}
|
|
11
|
+
return serialized.slice(0, 10000);
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
return `<JSON error: ${e.message}>`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=debug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":";;AACA,8BAYC;AAbD,0DAA0D;AAC1D,SAAgB,SAAS,CAAC,GAAQ;IAChC,IAAI,CAAC;QACH,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAChD,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CACrD,CAAC;QACF,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,UAAU,GAAG,EAAE,GAAG,GAAG,CAAC;QACxB,CAAC;QACD,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,gBAAgB,CAAC,CAAC,OAAO,GAAG,CAAC;IACtC,CAAC;AACH,CAAC"}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract an Ethereum address to a shorter string.
|
|
3
|
+
*
|
|
4
|
+
* Example:
|
|
5
|
+
* 0x1234567890123456789012345678901234567890
|
|
6
|
+
* becomes
|
|
7
|
+
* 0x1234…7890
|
|
8
|
+
*/
|
|
9
|
+
export declare function getAddressContraction(address: string, length?: number): string;
|
|
10
|
+
/** Convert a JS Date object to a UNIX timestamp. */
|
|
11
|
+
export declare function dateToUnix(d: Date): number;
|
|
12
|
+
/** Convert a UNIX timestamp to a JS Date object. */
|
|
13
|
+
export declare function unixToDate(unix: number): Date;
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAddressContraction = getAddressContraction;
|
|
4
|
+
exports.dateToUnix = dateToUnix;
|
|
5
|
+
exports.unixToDate = unixToDate;
|
|
6
|
+
/**
|
|
7
|
+
* Contract an Ethereum address to a shorter string.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
* 0x1234567890123456789012345678901234567890
|
|
11
|
+
* becomes
|
|
12
|
+
* 0x1234…7890
|
|
13
|
+
*/
|
|
14
|
+
function getAddressContraction(address, length = 4) {
|
|
15
|
+
return address.slice(0, 2 + length) + "…" + address.slice(-length);
|
|
16
|
+
}
|
|
17
|
+
/** Convert a JS Date object to a UNIX timestamp. */
|
|
18
|
+
function dateToUnix(d) {
|
|
19
|
+
return Math.floor(d.getTime() / 1000);
|
|
20
|
+
}
|
|
21
|
+
/** Convert a UNIX timestamp to a JS Date object. */
|
|
22
|
+
function unixToDate(unix) {
|
|
23
|
+
return new Date(unix * 1000);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":";;AAQA,sDAEC;AAGD,gCAEC;AAGD,gCAEC;AApBD;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CAAC,OAAe,EAAE,MAAM,GAAG,CAAC;IAC/D,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,GAAG,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,CAAC;AAED,oDAAoD;AACpD,SAAgB,UAAU,CAAC,CAAO;IAChC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,oDAAoD;AACpD,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./assert"), exports);
|
|
18
|
+
__exportStar(require("./chain"), exports);
|
|
19
|
+
__exportStar(require("./rozoPay"), exports);
|
|
20
|
+
__exportStar(require("./debug"), exports);
|
|
21
|
+
__exportStar(require("./format"), exports);
|
|
22
|
+
__exportStar(require("./primitiveTypes"), exports);
|
|
23
|
+
__exportStar(require("./retryBackoff"), exports);
|
|
24
|
+
__exportStar(require("./token"), exports);
|
|
25
|
+
__exportStar(require("./try"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,0CAAwB;AACxB,2CAAyB;AACzB,mDAAiC;AACjC,iDAA+B;AAC/B,0CAAwB;AACxB,wCAAsB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const zBigIntStr: z.ZodEffects<z.ZodString, `${bigint}`, string>;
|
|
3
|
+
export type BigIntStr = `${bigint}`;
|
|
4
|
+
export declare const zAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
5
|
+
export declare const zHex: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
6
|
+
export declare const zSolanaPublicKey: z.ZodString;
|
|
7
|
+
export type SolanaPublicKey = z.infer<typeof zSolanaPublicKey>;
|
|
8
|
+
export type PlatformType = "ios" | "android" | "other";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zSolanaPublicKey = exports.zHex = exports.zAddress = exports.zBigIntStr = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.zBigIntStr = zod_1.z
|
|
6
|
+
.string()
|
|
7
|
+
.regex(/^[0-9]+$/i)
|
|
8
|
+
.refine((s) => true);
|
|
9
|
+
exports.zAddress = zod_1.z
|
|
10
|
+
.string()
|
|
11
|
+
.regex(/^0x[0-9a-f]{40}$/i)
|
|
12
|
+
.refine((s) => true);
|
|
13
|
+
exports.zHex = zod_1.z
|
|
14
|
+
.string()
|
|
15
|
+
.regex(/^0x[0-9a-f]*$/i)
|
|
16
|
+
.refine((s) => true);
|
|
17
|
+
exports.zSolanaPublicKey = zod_1.z.string().regex(/^[1-9A-HJ-NP-Za-km-z]+$/);
|
|
18
|
+
//# sourceMappingURL=primitiveTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitiveTypes.js","sourceRoot":"","sources":["../src/primitiveTypes.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AAEX,QAAA,UAAU,GAAG,OAAC;KACxB,MAAM,EAAE;KACR,KAAK,CAAC,WAAW,CAAC;KAClB,MAAM,CAAC,CAAC,CAAC,EAAkB,EAAE,CAAC,IAAI,CAAC,CAAC;AAI1B,QAAA,QAAQ,GAAG,OAAC;KACtB,MAAM,EAAE;KACR,KAAK,CAAC,mBAAmB,CAAC;KAC1B,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,IAAI,CAAC,CAAC;AAExB,QAAA,IAAI,GAAG,OAAC;KAClB,MAAM,EAAE;KACR,KAAK,CAAC,gBAAgB,CAAC;KACvB,MAAM,CAAC,CAAC,CAAC,EAAY,EAAE,CAAC,IAAI,CAAC,CAAC;AAEpB,QAAA,gBAAgB,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retries a function up to a maximum number of times, with exponential backoff.
|
|
3
|
+
* Current settings, max total wait time is ~10 seconds.
|
|
4
|
+
*/
|
|
5
|
+
export declare function retryBackoff<T>(name: string, fn: () => Promise<T>, maxRetries?: number, backoffFn?: (i: number) => number): Promise<T>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retryBackoff = retryBackoff;
|
|
4
|
+
/**
|
|
5
|
+
* Retries a function up to a maximum number of times, with exponential backoff.
|
|
6
|
+
* Current settings, max total wait time is ~10 seconds.
|
|
7
|
+
*/
|
|
8
|
+
async function retryBackoff(name, fn, maxRetries = 5, backoffFn = (i) => Math.min(2000, 250 * 2 ** i)) {
|
|
9
|
+
for (let i = 1;; i++) {
|
|
10
|
+
try {
|
|
11
|
+
return await fn();
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
if (i <= maxRetries) {
|
|
15
|
+
const sleepMs = backoffFn(i);
|
|
16
|
+
console.error(`[RETRY] ${name} sleeping ${sleepMs}ms after try ${i}, error:`, e);
|
|
17
|
+
await new Promise((r) => setTimeout(r, sleepMs));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
console.warn(`[RETRY] ${name} QUITTING after try ${i}, error: ${e}`);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// TODO: add performance logging
|
|
26
|
+
throw new Error(`too many retries: ${name}`);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=retryBackoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryBackoff.js","sourceRoot":"","sources":["../src/retryBackoff.ts"],"names":[],"mappings":";;AAIA,oCAyBC;AA7BD;;;GAGG;AACI,KAAK,UAAU,YAAY,CAChC,IAAY,EACZ,EAAoB,EACpB,UAAU,GAAG,CAAC,EACd,YAAmC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IAEtE,KAAK,IAAI,CAAC,GAAG,CAAC,GAAI,CAAC,EAAE,EAAE,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC;gBACpB,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;gBAC7B,OAAO,CAAC,KAAK,CACX,WAAW,IAAI,aAAa,OAAO,gBAAgB,CAAC,UAAU,EAC9D,CAAC,CACF,CAAC;gBACF,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;YACnD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,WAAW,IAAI,uBAAuB,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;gBACrE,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IACD,gCAAgC;IAChC,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;AAC/C,CAAC"}
|