@silvana-one/mina-utils 0.2.0
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 +201 -0
- package/README.md +1 -0
- package/dist/node/config.d.ts +4 -0
- package/dist/node/config.js +5 -0
- package/dist/node/config.js.map +1 -0
- package/dist/node/index.cjs +1325 -0
- package/dist/node/index.d.ts +6 -0
- package/dist/node/index.js +7 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/networks.d.ts +32 -0
- package/dist/node/networks.js +81 -0
- package/dist/node/networks.js.map +1 -0
- package/dist/node/storage/index.d.ts +2 -0
- package/dist/node/storage/index.js +3 -0
- package/dist/node/storage/index.js.map +1 -0
- package/dist/node/storage/ipfs.d.ts +5 -0
- package/dist/node/storage/ipfs.js +16 -0
- package/dist/node/storage/ipfs.js.map +1 -0
- package/dist/node/storage/pinata.d.ts +6 -0
- package/dist/node/storage/pinata.js +40 -0
- package/dist/node/storage/pinata.js.map +1 -0
- package/dist/node/transactions/account.d.ts +4 -0
- package/dist/node/transactions/account.js +44 -0
- package/dist/node/transactions/account.js.map +1 -0
- package/dist/node/transactions/blockberry.d.ts +21 -0
- package/dist/node/transactions/blockberry.js +130 -0
- package/dist/node/transactions/blockberry.js.map +1 -0
- package/dist/node/transactions/chain.d.ts +1 -0
- package/dist/node/transactions/chain.js +2 -0
- package/dist/node/transactions/chain.js.map +1 -0
- package/dist/node/transactions/index.d.ts +8 -0
- package/dist/node/transactions/index.js +9 -0
- package/dist/node/transactions/index.js.map +1 -0
- package/dist/node/transactions/nonce.d.ts +17 -0
- package/dist/node/transactions/nonce.js +91 -0
- package/dist/node/transactions/nonce.js.map +1 -0
- package/dist/node/transactions/send.d.ts +31 -0
- package/dist/node/transactions/send.js +154 -0
- package/dist/node/transactions/send.js.map +1 -0
- package/dist/node/transactions/tiny-contract.d.ts +5 -0
- package/dist/node/transactions/tiny-contract.js +22 -0
- package/dist/node/transactions/tiny-contract.js.map +1 -0
- package/dist/node/transactions/transaction.d.ts +21 -0
- package/dist/node/transactions/transaction.js +222 -0
- package/dist/node/transactions/transaction.js.map +1 -0
- package/dist/node/transactions/txstatus.d.ts +8 -0
- package/dist/node/transactions/txstatus.js +16 -0
- package/dist/node/transactions/txstatus.js.map +1 -0
- package/dist/node/utils/base64-field.d.ts +5 -0
- package/dist/node/utils/base64-field.js +29 -0
- package/dist/node/utils/base64-field.js.map +1 -0
- package/dist/node/utils/base64.d.ts +6 -0
- package/dist/node/utils/base64.js +83 -0
- package/dist/node/utils/base64.js.map +1 -0
- package/dist/node/utils/fee.d.ts +6 -0
- package/dist/node/utils/fee.js +11 -0
- package/dist/node/utils/fee.js.map +1 -0
- package/dist/node/utils/fetch.d.ts +44 -0
- package/dist/node/utils/fetch.js +101 -0
- package/dist/node/utils/fetch.js.map +1 -0
- package/dist/node/utils/fields.d.ts +13 -0
- package/dist/node/utils/fields.js +39 -0
- package/dist/node/utils/fields.js.map +1 -0
- package/dist/node/utils/index.d.ts +8 -0
- package/dist/node/utils/index.js +9 -0
- package/dist/node/utils/index.js.map +1 -0
- package/dist/node/utils/indexed-map.d.ts +32 -0
- package/dist/node/utils/indexed-map.js +124 -0
- package/dist/node/utils/indexed-map.js.map +1 -0
- package/dist/node/utils/mina.d.ts +39 -0
- package/dist/node/utils/mina.js +123 -0
- package/dist/node/utils/mina.js.map +1 -0
- package/dist/node/utils/utils.d.ts +8 -0
- package/dist/node/utils/utils.js +61 -0
- package/dist/node/utils/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/tsconfig.web.tsbuildinfo +1 -0
- package/dist/web/config.d.ts +4 -0
- package/dist/web/config.js +5 -0
- package/dist/web/config.js.map +1 -0
- package/dist/web/index.d.ts +6 -0
- package/dist/web/index.js +7 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/networks.d.ts +32 -0
- package/dist/web/networks.js +81 -0
- package/dist/web/networks.js.map +1 -0
- package/dist/web/storage/index.d.ts +2 -0
- package/dist/web/storage/index.js +3 -0
- package/dist/web/storage/index.js.map +1 -0
- package/dist/web/storage/ipfs.d.ts +5 -0
- package/dist/web/storage/ipfs.js +16 -0
- package/dist/web/storage/ipfs.js.map +1 -0
- package/dist/web/storage/pinata.d.ts +6 -0
- package/dist/web/storage/pinata.js +40 -0
- package/dist/web/storage/pinata.js.map +1 -0
- package/dist/web/transactions/account.d.ts +4 -0
- package/dist/web/transactions/account.js +44 -0
- package/dist/web/transactions/account.js.map +1 -0
- package/dist/web/transactions/blockberry.d.ts +21 -0
- package/dist/web/transactions/blockberry.js +130 -0
- package/dist/web/transactions/blockberry.js.map +1 -0
- package/dist/web/transactions/chain.d.ts +1 -0
- package/dist/web/transactions/chain.js +2 -0
- package/dist/web/transactions/chain.js.map +1 -0
- package/dist/web/transactions/index.d.ts +8 -0
- package/dist/web/transactions/index.js +9 -0
- package/dist/web/transactions/index.js.map +1 -0
- package/dist/web/transactions/nonce.d.ts +17 -0
- package/dist/web/transactions/nonce.js +91 -0
- package/dist/web/transactions/nonce.js.map +1 -0
- package/dist/web/transactions/send.d.ts +31 -0
- package/dist/web/transactions/send.js +154 -0
- package/dist/web/transactions/send.js.map +1 -0
- package/dist/web/transactions/tiny-contract.d.ts +5 -0
- package/dist/web/transactions/tiny-contract.js +22 -0
- package/dist/web/transactions/tiny-contract.js.map +1 -0
- package/dist/web/transactions/transaction.d.ts +21 -0
- package/dist/web/transactions/transaction.js +222 -0
- package/dist/web/transactions/transaction.js.map +1 -0
- package/dist/web/transactions/txstatus.d.ts +8 -0
- package/dist/web/transactions/txstatus.js +16 -0
- package/dist/web/transactions/txstatus.js.map +1 -0
- package/dist/web/utils/base64-field.d.ts +5 -0
- package/dist/web/utils/base64-field.js +29 -0
- package/dist/web/utils/base64-field.js.map +1 -0
- package/dist/web/utils/base64.d.ts +6 -0
- package/dist/web/utils/base64.js +83 -0
- package/dist/web/utils/base64.js.map +1 -0
- package/dist/web/utils/fee.d.ts +6 -0
- package/dist/web/utils/fee.js +11 -0
- package/dist/web/utils/fee.js.map +1 -0
- package/dist/web/utils/fetch.d.ts +44 -0
- package/dist/web/utils/fetch.js +101 -0
- package/dist/web/utils/fetch.js.map +1 -0
- package/dist/web/utils/fields.d.ts +13 -0
- package/dist/web/utils/fields.js +39 -0
- package/dist/web/utils/fields.js.map +1 -0
- package/dist/web/utils/index.d.ts +8 -0
- package/dist/web/utils/index.js +9 -0
- package/dist/web/utils/index.js.map +1 -0
- package/dist/web/utils/indexed-map.d.ts +32 -0
- package/dist/web/utils/indexed-map.js +124 -0
- package/dist/web/utils/indexed-map.js.map +1 -0
- package/dist/web/utils/mina.d.ts +39 -0
- package/dist/web/utils/mina.js +123 -0
- package/dist/web/utils/mina.js.map +1 -0
- package/dist/web/utils/utils.d.ts +8 -0
- package/dist/web/utils/utils.js +61 -0
- package/dist/web/utils/utils.js.map +1 -0
- package/package.json +62 -0
- package/src/config.ts +5 -0
- package/src/index.ts +6 -0
- package/src/networks.ts +130 -0
- package/src/storage/index.ts +2 -0
- package/src/storage/ipfs.ts +20 -0
- package/src/storage/pinata.ts +56 -0
- package/src/transactions/account.ts +57 -0
- package/src/transactions/blockberry.ts +198 -0
- package/src/transactions/chain.ts +1 -0
- package/src/transactions/index.ts +8 -0
- package/src/transactions/nonce.ts +121 -0
- package/src/transactions/send.ts +228 -0
- package/src/transactions/tiny-contract.ts +9 -0
- package/src/transactions/transaction.ts +319 -0
- package/src/transactions/txstatus.ts +26 -0
- package/src/utils/base64-field.ts +34 -0
- package/src/utils/base64.ts +87 -0
- package/src/utils/fee.ts +11 -0
- package/src/utils/fetch.ts +130 -0
- package/src/utils/fields.ts +39 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/indexed-map.ts +170 -0
- package/src/utils/mina.ts +171 -0
- package/src/utils/utils.ts +79 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { checkZkappTransaction } from "o1js";
|
|
2
|
+
import { sleep } from "../utils/utils.js";
|
|
3
|
+
import { fetchMinaAccount } from "../utils/fetch.js";
|
|
4
|
+
import { getCurrentNetwork } from "../utils/mina.js";
|
|
5
|
+
/**
|
|
6
|
+
* The function `sendTx` sends a transaction, checks account updates, and waits for
|
|
7
|
+
* confirmation on the blockchain.
|
|
8
|
+
* @param params The parameters object
|
|
9
|
+
* @param params.tx The transaction to send
|
|
10
|
+
* @param params.description A description of the transaction
|
|
11
|
+
* @param params.verbose Whether to log verbose information
|
|
12
|
+
* @param params.wait Whether to wait for the transaction to be included in a block
|
|
13
|
+
* @param params.chain The blockchain to send the transaction on
|
|
14
|
+
* @returns The `sendTx` function returns a `Mina.IncludedTransaction`, `Mina.PendingTransaction`,
|
|
15
|
+
* `Mina.RejectedTransaction`, or `undefined` if there was an error during the process.
|
|
16
|
+
*/
|
|
17
|
+
export async function sendTx(params) {
|
|
18
|
+
const { tx, description = "", verbose = true, wait = true, chain = getCurrentNetwork().network.chainId, delay = chain === "zeko" || chain === "lightnet" ? 5000 : 60000, retry = 30, } = params;
|
|
19
|
+
// flatten accountUpdates
|
|
20
|
+
const accountUpdates = JSON.parse(tx.toJSON()).accountUpdates;
|
|
21
|
+
const auCount = [];
|
|
22
|
+
let proofAuthorizationCount = 0;
|
|
23
|
+
// Calculate the number of account updates for each { publicKey, tokenId }
|
|
24
|
+
for (const au of accountUpdates) {
|
|
25
|
+
const { publicKey, tokenId, authorizationKind } = au.body;
|
|
26
|
+
if (au.authorization.proof) {
|
|
27
|
+
proofAuthorizationCount++;
|
|
28
|
+
if (authorizationKind.isProved === false)
|
|
29
|
+
console.error("Proof authorization exists but isProved is false");
|
|
30
|
+
}
|
|
31
|
+
else if (authorizationKind.isProved === true)
|
|
32
|
+
console.error("isProved is true but no proof authorization");
|
|
33
|
+
const index = auCount.findIndex((item) => item.publicKey === publicKey && item.tokenId === tokenId);
|
|
34
|
+
if (index === -1)
|
|
35
|
+
auCount.push({ publicKey, tokenId, count: 1 });
|
|
36
|
+
else
|
|
37
|
+
auCount[index].count++;
|
|
38
|
+
}
|
|
39
|
+
if (verbose)
|
|
40
|
+
console.log(`Account updates for ${description ?? "tx"}: ${auCount.length}, proof authorizations: ${proofAuthorizationCount}`);
|
|
41
|
+
for (const au of auCount) {
|
|
42
|
+
if (au.count > 1)
|
|
43
|
+
if (verbose)
|
|
44
|
+
console.log(`DUPLICATE AU ${description ?? ""}: ${au.publicKey} ${au.tokenId !== "wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf"
|
|
45
|
+
? "tokenId: " + au.tokenId
|
|
46
|
+
: ""} count: ${au.count}`);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
let txSent;
|
|
50
|
+
let sent = false;
|
|
51
|
+
let attempt = 1;
|
|
52
|
+
while (!sent && attempt <= retry) {
|
|
53
|
+
txSent = await tx.safeSend();
|
|
54
|
+
if (txSent.status === "pending") {
|
|
55
|
+
sent = true;
|
|
56
|
+
if (verbose)
|
|
57
|
+
console.log(`${description ?? ""} tx sent: hash: ${txSent.hash} status: ${txSent.status}`);
|
|
58
|
+
}
|
|
59
|
+
else if (chain !== "local") {
|
|
60
|
+
attempt++;
|
|
61
|
+
console.error(`${description} tx NOT sent: hash: ${txSent?.hash} status: ${txSent?.status}, errors: ${String(txSent.errors ?? "")}`);
|
|
62
|
+
if (verbose)
|
|
63
|
+
console.log(`Retrying ${chain} tx, retry:`, attempt);
|
|
64
|
+
await sleep(10000 * attempt);
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
attempt = retry + 1; // local chain - do not retry
|
|
68
|
+
}
|
|
69
|
+
if (txSent === undefined)
|
|
70
|
+
throw new Error("txSent is undefined");
|
|
71
|
+
if ((txSent.errors?.length ?? 0) > 0) {
|
|
72
|
+
console.error(`${description ?? ""} tx error: hash: ${txSent.hash} status: ${txSent.status} errors: ${String(txSent.errors ?? "")}`);
|
|
73
|
+
}
|
|
74
|
+
if (txSent.status === "pending" && wait !== false && chain !== "zeko") {
|
|
75
|
+
if (verbose)
|
|
76
|
+
console.log(`Waiting for tx inclusion...`);
|
|
77
|
+
let txIncluded = await txSent.safeWait();
|
|
78
|
+
if (txIncluded.status !== "included") {
|
|
79
|
+
console.error(`${description ?? ""} tx NOT included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}, errors: ${String(txIncluded.errors ?? "")}`);
|
|
80
|
+
}
|
|
81
|
+
if (chain !== "local") {
|
|
82
|
+
// we still wait for the tx to be included in the block by checking the nonce
|
|
83
|
+
// even in the case of tx NOT included
|
|
84
|
+
// because the tx might still be included in the block in the case of devnet instability
|
|
85
|
+
const { publicKey, nonce } = tx.transaction.feePayer.body;
|
|
86
|
+
const started = Date.now();
|
|
87
|
+
while (Date.now() - started < 1000 * 60 * 10) {
|
|
88
|
+
const newNonce = (await fetchMinaAccount({
|
|
89
|
+
publicKey,
|
|
90
|
+
force: true,
|
|
91
|
+
})).account?.nonce;
|
|
92
|
+
if (newNonce &&
|
|
93
|
+
Number(newNonce.toBigint()) > Number(nonce.toBigint())) {
|
|
94
|
+
let txIncluded = await txSent.safeWait();
|
|
95
|
+
if (txIncluded.status === "included") {
|
|
96
|
+
if (verbose)
|
|
97
|
+
console.log(`${description ?? ""} tx included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
|
98
|
+
if (delay > 0)
|
|
99
|
+
await sleep(delay);
|
|
100
|
+
return txIncluded;
|
|
101
|
+
}
|
|
102
|
+
else if (txIncluded.status === "rejected") {
|
|
103
|
+
// We never should see this error as the nonce is updated (except when tx failed due to a preconditions),
|
|
104
|
+
// so we retry to check if the tx is included
|
|
105
|
+
console.error(`tx rejected: ${chain}: hash: ${txIncluded.hash} status: ${txIncluded.status} errors: ${txIncluded.errors}`);
|
|
106
|
+
await sleep(30000);
|
|
107
|
+
txIncluded = await txSent.safeWait();
|
|
108
|
+
if (txIncluded.status === "included") {
|
|
109
|
+
if (verbose)
|
|
110
|
+
console.log(`${description ?? ""} tx included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
|
111
|
+
if (delay > 0)
|
|
112
|
+
await sleep(delay);
|
|
113
|
+
return txIncluded;
|
|
114
|
+
}
|
|
115
|
+
console.error(`tx failed: ${chain}: hash: ${txIncluded.hash} status: ${txIncluded.status} errors: ${txIncluded.errors}`);
|
|
116
|
+
return txIncluded;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (verbose)
|
|
120
|
+
console.log(`Waiting for ${chain} to update state for ${Math.floor((Date.now() - started) / 1000)} sec...`);
|
|
121
|
+
await sleep(30000);
|
|
122
|
+
}
|
|
123
|
+
// finally, if the tx is still not included, show an error
|
|
124
|
+
console.error(`${chain} do not reflect nonce update for tx ${txIncluded.hash} with status ${txIncluded.status}`);
|
|
125
|
+
}
|
|
126
|
+
if (verbose)
|
|
127
|
+
console.log(`${description ?? ""} tx included into block: hash: ${txIncluded.hash} status: ${txIncluded.status}`);
|
|
128
|
+
return txIncluded;
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
return txSent;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (chain !== "zeko")
|
|
135
|
+
console.error("Error sending tx", error);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export async function getTxStatusFast(params) {
|
|
139
|
+
const { hash, chain = getCurrentNetwork().network.chainId } = params;
|
|
140
|
+
if (chain === "local" || chain === "zeko")
|
|
141
|
+
return { success: true, result: true };
|
|
142
|
+
try {
|
|
143
|
+
const txStatus = await checkZkappTransaction(hash);
|
|
144
|
+
return {
|
|
145
|
+
success: true,
|
|
146
|
+
result: txStatus?.success ?? false,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.error("getTxStatusFast error while getting tx status - catch", hash, error);
|
|
151
|
+
return { success: false, error: error?.message ?? "Cannot get tx status" };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=send.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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E,CAChC,CAAC;YACJ,OAAO,UAAU,CAAC;QACpB,CAAC;;YAAM,OAAO,MAAM,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,KAAK,MAAM;YAAE,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAGrC;IACC,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,iBAAiB,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC;IACrE,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM;QACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAEzC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACnD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,QAAQ,EAAE,OAAO,IAAI,KAAK;SACnC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CACX,uDAAuD,EACvD,IAAI,EACJ,KAAK,CACN,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,IAAI,sBAAsB,EAAE,CAAC;IAC7E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Field, SmartContract, method, state, State } from "o1js";
|
|
3
|
+
export class TinyContract extends SmartContract {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.value = State();
|
|
7
|
+
}
|
|
8
|
+
async setValue(value) {
|
|
9
|
+
this.value.set(value);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
__decorate([
|
|
13
|
+
state(Field),
|
|
14
|
+
__metadata("design:type", Object)
|
|
15
|
+
], TinyContract.prototype, "value", void 0);
|
|
16
|
+
__decorate([
|
|
17
|
+
method,
|
|
18
|
+
__metadata("design:type", Function),
|
|
19
|
+
__metadata("design:paramtypes", [Field]),
|
|
20
|
+
__metadata("design:returntype", Promise)
|
|
21
|
+
], TinyContract.prototype, "setValue", null);
|
|
22
|
+
//# sourceMappingURL=tiny-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiny-contract.js","sourceRoot":"","sources":["../../../src/transactions/tiny-contract.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAElE,MAAM,OAAO,YAAa,SAAQ,aAAa;IAA/C;;QACgB,UAAK,GAAG,KAAK,EAAS,CAAC;IAKvC,CAAC;IAHe,AAAN,KAAK,CAAC,QAAQ,CAAC,KAAY;QACjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;CACF;AALe;IAAb,KAAK,CAAC,KAAK,CAAC;;2CAAwB;AAEvB;IAAb,MAAM;;qCAAuB,KAAK;;4CAElC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PublicKey, Transaction, Mina, UInt64 } from "o1js";
|
|
2
|
+
import { TransactionPayloads } from "@silvana-one/api";
|
|
3
|
+
export declare function createTransactionPayloads(tx: Mina.Transaction<false, false> | Mina.Transaction<false, true>): TransactionPayloads;
|
|
4
|
+
export declare function transactionParams(params: {
|
|
5
|
+
proverPayload: string;
|
|
6
|
+
signedData: string;
|
|
7
|
+
} | TransactionPayloads): {
|
|
8
|
+
fee: UInt64;
|
|
9
|
+
sender: PublicKey;
|
|
10
|
+
nonce: number;
|
|
11
|
+
memo: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function parseTransactionPayloads(params: {
|
|
14
|
+
proverPayload: string;
|
|
15
|
+
signedData: string;
|
|
16
|
+
txNew: Mina.Transaction<false, false> | Mina.Transaction<false, true>;
|
|
17
|
+
} | {
|
|
18
|
+
payloads: TransactionPayloads;
|
|
19
|
+
txNew: Mina.Transaction<false, false> | Mina.Transaction<false, true>;
|
|
20
|
+
}): Transaction<false, true>;
|
|
21
|
+
export declare function serializeTransaction(tx: Mina.Transaction<false, false> | Mina.Transaction<false, true>): string;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Field, PublicKey, Mina, UInt64 } from "o1js";
|
|
2
|
+
import { fieldToBase64, fieldFromBase64 } from "../utils/base64-field.js";
|
|
3
|
+
export function createTransactionPayloads(tx) {
|
|
4
|
+
const transaction = tx.toJSON();
|
|
5
|
+
const txJSON = JSON.parse(transaction);
|
|
6
|
+
const signedData = JSON.stringify({ zkappCommand: txJSON });
|
|
7
|
+
const proverPayload = serializeTransaction(tx);
|
|
8
|
+
const fee = tx.transaction.feePayer.body.fee.toJSON();
|
|
9
|
+
const sender = tx.transaction.feePayer.body.publicKey.toBase58();
|
|
10
|
+
const nonce = Number(tx.transaction.feePayer.body.nonce.toBigint());
|
|
11
|
+
const memo = tx.transaction.memo;
|
|
12
|
+
const minaSignerPayload = {
|
|
13
|
+
zkappCommand: txJSON,
|
|
14
|
+
feePayer: {
|
|
15
|
+
feePayer: sender,
|
|
16
|
+
fee,
|
|
17
|
+
nonce,
|
|
18
|
+
memo,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const walletPayload = {
|
|
22
|
+
transaction,
|
|
23
|
+
nonce,
|
|
24
|
+
onlySign: true,
|
|
25
|
+
feePayer: {
|
|
26
|
+
fee,
|
|
27
|
+
memo,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
sender,
|
|
32
|
+
nonce,
|
|
33
|
+
memo,
|
|
34
|
+
fee,
|
|
35
|
+
walletPayload,
|
|
36
|
+
minaSignerPayload,
|
|
37
|
+
proverPayload,
|
|
38
|
+
signedData,
|
|
39
|
+
transaction,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function transactionParams(params) {
|
|
43
|
+
const { proverPayload, signedData } = params;
|
|
44
|
+
const signedJson = JSON.parse(signedData);
|
|
45
|
+
const { sender, tx } = JSON.parse(proverPayload);
|
|
46
|
+
const transaction = Mina.Transaction.fromJSON(JSON.parse(tx));
|
|
47
|
+
const memo = transaction.transaction.memo;
|
|
48
|
+
return {
|
|
49
|
+
fee: UInt64.from(signedJson.zkappCommand.feePayer.body.fee),
|
|
50
|
+
sender: PublicKey.fromBase58(sender),
|
|
51
|
+
nonce: Number(signedJson.zkappCommand.feePayer.body.nonce),
|
|
52
|
+
memo,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function parseTransactionPayloads(params) {
|
|
56
|
+
const { txNew } = params;
|
|
57
|
+
const proverPayload = "payloads" in params ? params.payloads.proverPayload : params.proverPayload;
|
|
58
|
+
const signedData = "payloads" in params ? params.payloads.signedData : params.signedData;
|
|
59
|
+
const signedJson = JSON.parse(signedData);
|
|
60
|
+
const { tx, blindingValues, length, forestJSONs } = JSON.parse(proverPayload);
|
|
61
|
+
const transaction = Mina.Transaction.fromJSON(JSON.parse(tx));
|
|
62
|
+
const forests = forestJSONs.map((f) => JSON.parse(f));
|
|
63
|
+
if (length !== txNew.transaction.accountUpdates.length) {
|
|
64
|
+
throw new Error(`New Transaction length mismatch: ${length} !== ${txNew.transaction.accountUpdates.length}`);
|
|
65
|
+
}
|
|
66
|
+
if (length !== transaction.transaction.accountUpdates.length) {
|
|
67
|
+
throw new Error(`Serialized Transaction length mismatch: ${length} !== ${transaction.transaction.accountUpdates.length}`);
|
|
68
|
+
}
|
|
69
|
+
for (let i = 0; i < length; i++) {
|
|
70
|
+
transaction.transaction.accountUpdates[i].lazyAuthorization =
|
|
71
|
+
txNew.transaction.accountUpdates[i].lazyAuthorization;
|
|
72
|
+
if (blindingValues[i] !== "") {
|
|
73
|
+
if (transaction.transaction.accountUpdates[i].lazyAuthorization ===
|
|
74
|
+
undefined ||
|
|
75
|
+
transaction.transaction.accountUpdates[i].lazyAuthorization
|
|
76
|
+
.blindingValue === undefined) {
|
|
77
|
+
throw new Error(`Lazy authorization blinding value is undefined for item ${i}`);
|
|
78
|
+
}
|
|
79
|
+
transaction.transaction.accountUpdates[i].lazyAuthorization.blindingValue = Field.fromJSON(blindingValues[i]);
|
|
80
|
+
}
|
|
81
|
+
if (forests[i].length > 0) {
|
|
82
|
+
if (transaction.transaction.accountUpdates[i].lazyAuthorization ===
|
|
83
|
+
undefined ||
|
|
84
|
+
transaction.transaction.accountUpdates[i].lazyAuthorization
|
|
85
|
+
.args === undefined) {
|
|
86
|
+
throw new Error(`Lazy authorization args is undefined for item ${i}`);
|
|
87
|
+
}
|
|
88
|
+
deserializeLazyAuthorization(transaction.transaction.accountUpdates[i].lazyAuthorization
|
|
89
|
+
.args, forests[i]);
|
|
90
|
+
if (forests[i].restoredItems !== forests[i].length) {
|
|
91
|
+
throw new Error(`Forest ${i} not fully restored`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
transaction.transaction.feePayer.authorization =
|
|
96
|
+
signedJson.zkappCommand.feePayer.authorization;
|
|
97
|
+
transaction.transaction.feePayer.body.fee = UInt64.from(signedJson.zkappCommand.feePayer.body.fee);
|
|
98
|
+
for (let i = 0; i < length; i++) {
|
|
99
|
+
const signature = signedJson.zkappCommand.accountUpdates[i].authorization.signature;
|
|
100
|
+
if (signature !== undefined && signature !== null) {
|
|
101
|
+
transaction.transaction.accountUpdates[i].authorization.signature =
|
|
102
|
+
signedJson.zkappCommand.accountUpdates[i].authorization.signature;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return transaction;
|
|
106
|
+
}
|
|
107
|
+
export function serializeTransaction(tx) {
|
|
108
|
+
const length = tx.transaction.accountUpdates.length;
|
|
109
|
+
let i;
|
|
110
|
+
const blindingValues = [];
|
|
111
|
+
const forests = [];
|
|
112
|
+
for (i = 0; i < length; i++) {
|
|
113
|
+
const la = tx.transaction.accountUpdates[i].lazyAuthorization;
|
|
114
|
+
if (la !== undefined &&
|
|
115
|
+
la.blindingValue !== undefined &&
|
|
116
|
+
la.kind === "lazy-proof")
|
|
117
|
+
blindingValues.push(la.blindingValue.toJSON());
|
|
118
|
+
else
|
|
119
|
+
blindingValues.push("");
|
|
120
|
+
const forest = { length: 0, items: [] };
|
|
121
|
+
serializeLazyAuthorization(tx.transaction.accountUpdates[i].lazyAuthorization?.args, forest);
|
|
122
|
+
forests.push(forest);
|
|
123
|
+
}
|
|
124
|
+
const serializedTransaction = JSON.stringify({
|
|
125
|
+
tx: tx.toJSON(),
|
|
126
|
+
blindingValues,
|
|
127
|
+
forestJSONs: forests.map((f) => JSON.stringify(f)),
|
|
128
|
+
length,
|
|
129
|
+
fee: tx.transaction.feePayer.body.fee.toJSON(),
|
|
130
|
+
sender: tx.transaction.feePayer.body.publicKey.toBase58(),
|
|
131
|
+
nonce: tx.transaction.feePayer.body.nonce.toBigint().toString(),
|
|
132
|
+
}, null, 2);
|
|
133
|
+
return serializedTransaction;
|
|
134
|
+
}
|
|
135
|
+
function serializeLazyAuthorization(lazyAuthorization, serialized) {
|
|
136
|
+
if (lazyAuthorization?.hash !== undefined && lazyAuthorization.hash.toJSON) {
|
|
137
|
+
serialized.items.push({
|
|
138
|
+
h: fieldToBase64(lazyAuthorization.hash),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (lazyAuthorization?.previousHash !== undefined &&
|
|
142
|
+
lazyAuthorization.previousHash.toJSON) {
|
|
143
|
+
serialized.items.push({
|
|
144
|
+
p: fieldToBase64(lazyAuthorization.previousHash),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (lazyAuthorization?.callData !== undefined &&
|
|
148
|
+
lazyAuthorization.callData.toJSON) {
|
|
149
|
+
serialized.items.push({
|
|
150
|
+
c: fieldToBase64(lazyAuthorization.callData),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (lazyAuthorization?.id !== undefined) {
|
|
154
|
+
serialized.items.push({
|
|
155
|
+
i: lazyAuthorization.id,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (Array.isArray(lazyAuthorization)) {
|
|
159
|
+
for (const item of lazyAuthorization) {
|
|
160
|
+
serializeLazyAuthorization(item, serialized);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (typeof lazyAuthorization === "object") {
|
|
164
|
+
for (const key in lazyAuthorization) {
|
|
165
|
+
serializeLazyAuthorization(lazyAuthorization[key], serialized);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
serialized.length = serialized.items.length;
|
|
169
|
+
}
|
|
170
|
+
function deserializeLazyAuthorization(lazyAuthorization, serialized) {
|
|
171
|
+
if (serialized.restoredItems === undefined)
|
|
172
|
+
serialized.restoredItems = 0;
|
|
173
|
+
if (lazyAuthorization?.hash !== undefined && lazyAuthorization.hash.toJSON) {
|
|
174
|
+
if (serialized.restoredItems >= serialized.length)
|
|
175
|
+
throw new Error("Restored more items than expected");
|
|
176
|
+
const hash = serialized.items[serialized.restoredItems].h;
|
|
177
|
+
if (hash === undefined)
|
|
178
|
+
throw new Error(`Hash is undefined for item ${serialized.restoredItems}`);
|
|
179
|
+
lazyAuthorization.hash = fieldFromBase64(hash);
|
|
180
|
+
serialized.restoredItems++;
|
|
181
|
+
}
|
|
182
|
+
if (lazyAuthorization?.previousHash !== undefined &&
|
|
183
|
+
lazyAuthorization.previousHash.toJSON) {
|
|
184
|
+
if (serialized.restoredItems >= serialized.length)
|
|
185
|
+
throw new Error("Restored more items than expected");
|
|
186
|
+
const previousHash = serialized.items[serialized.restoredItems].p;
|
|
187
|
+
if (previousHash === undefined)
|
|
188
|
+
throw new Error(`Previous hash is undefined for item ${serialized.restoredItems}`);
|
|
189
|
+
lazyAuthorization.previousHash = fieldFromBase64(previousHash);
|
|
190
|
+
serialized.restoredItems++;
|
|
191
|
+
}
|
|
192
|
+
if (lazyAuthorization?.callData !== undefined &&
|
|
193
|
+
lazyAuthorization.callData.toJSON) {
|
|
194
|
+
if (serialized.restoredItems >= serialized.length)
|
|
195
|
+
throw new Error("Restored more items than expected");
|
|
196
|
+
const callData = serialized.items[serialized.restoredItems].c;
|
|
197
|
+
if (callData === undefined)
|
|
198
|
+
throw new Error(`Call data is undefined for item ${serialized.restoredItems}`);
|
|
199
|
+
lazyAuthorization.callData = fieldFromBase64(callData);
|
|
200
|
+
serialized.restoredItems++;
|
|
201
|
+
}
|
|
202
|
+
if (lazyAuthorization?.id !== undefined) {
|
|
203
|
+
if (serialized.restoredItems >= serialized.length)
|
|
204
|
+
throw new Error("Restored more items than expected");
|
|
205
|
+
const id = serialized.items[serialized.restoredItems].i;
|
|
206
|
+
if (id === undefined)
|
|
207
|
+
throw new Error(`Id is undefined for item ${serialized.restoredItems}`);
|
|
208
|
+
lazyAuthorization.id = id;
|
|
209
|
+
serialized.restoredItems++;
|
|
210
|
+
}
|
|
211
|
+
if (Array.isArray(lazyAuthorization)) {
|
|
212
|
+
for (const item of lazyAuthorization) {
|
|
213
|
+
deserializeLazyAuthorization(item, serialized);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (typeof lazyAuthorization === "object") {
|
|
217
|
+
for (const key in lazyAuthorization) {
|
|
218
|
+
deserializeLazyAuthorization(lazyAuthorization[key], serialized);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/transactions/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAe,IAAI,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE1E,M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Aa,CAAC,CAAC,CAAC,CAAC;QACxD,IAAI,EAAE,KAAK,SAAS;YAClB,MAAM,IAAI,KAAK,CAAC,4BAA4B,UAAU,CAAC,aAAa,EAAE,CAAC,CAAC;QAC1E,iBAAiB,CAAC,EAAE,GAAG,EAAE,CAAC;QAC1B,UAAU,CAAC,aAAa,EAAE,CAAC;IAC7B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;YACrC,4BAA4B,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;QAC1C,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;YACpC,4BAA4B,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getZkAppTxFromBlockBerry } from "./blockberry.js";
|
|
2
|
+
const TIMEOUT = 1000 * 60 * 21;
|
|
3
|
+
export async function txStatusBlockberry(params) {
|
|
4
|
+
const { hash, chain, time, blockBerryApiKey } = params;
|
|
5
|
+
const tx = await getZkAppTxFromBlockBerry({ hash, chain, blockBerryApiKey });
|
|
6
|
+
if (tx?.txStatus)
|
|
7
|
+
return tx?.txStatus;
|
|
8
|
+
if (Date.now() - time > (params.timeout ?? TIMEOUT)) {
|
|
9
|
+
console.error("txStatus: Timeout while checking tx with blockberry", chain, hash);
|
|
10
|
+
return "replaced";
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return "pending";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=txstatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"txstatus.js","sourceRoot":"","sources":["../../../src/transactions/txstatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;AAE/B,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAMxC;IACC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IAEvD,MAAM,EAAE,GAAG,MAAM,wBAAwB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC7E,IAAI,EAAE,EAAE,QAAQ;QAAE,OAAO,EAAE,EAAE,QAAQ,CAAC;IACtC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC;QACpD,OAAO,CAAC,KAAK,CACX,qDAAqD,EACrD,KAAK,EACL,IAAI,CACL,CAAC;QACF,OAAO,UAAU,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Field } from "o1js";
|
|
2
|
+
export declare function fieldToBase56(field: Field): string;
|
|
3
|
+
export declare function fieldFromBase56(str: string): Field;
|
|
4
|
+
export declare function fieldToBase64(field: Field): string;
|
|
5
|
+
export declare function fieldFromBase64(str: string): Field;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Field } from "o1js";
|
|
2
|
+
import { toBase, fromBase } from "./base64.js";
|
|
3
|
+
// URL friendly base64 encoding
|
|
4
|
+
const TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
5
|
+
export function fieldToBase56(field) {
|
|
6
|
+
const digits = toBase(field.toBigInt(), 56n);
|
|
7
|
+
//console.log("digits:", digits);
|
|
8
|
+
const str = digits.map((x) => TABLE[Number(x)]).join("");
|
|
9
|
+
//console.log("str:", str);
|
|
10
|
+
return str;
|
|
11
|
+
}
|
|
12
|
+
export function fieldFromBase56(str) {
|
|
13
|
+
const base56Digits = str.split("").map((x) => BigInt(TABLE.indexOf(x)));
|
|
14
|
+
const x = fromBase(base56Digits, 56n);
|
|
15
|
+
return Field(x);
|
|
16
|
+
}
|
|
17
|
+
export function fieldToBase64(field) {
|
|
18
|
+
const digits = toBase(field.toBigInt(), 64n);
|
|
19
|
+
//console.log("digits:", digits);
|
|
20
|
+
const str = digits.map((x) => TABLE[Number(x)]).join("");
|
|
21
|
+
//console.log("str:", str);
|
|
22
|
+
return str;
|
|
23
|
+
}
|
|
24
|
+
export function fieldFromBase64(str) {
|
|
25
|
+
const base64Digits = str.split("").map((x) => BigInt(TABLE.indexOf(x)));
|
|
26
|
+
const x = fromBase(base64Digits, 64n);
|
|
27
|
+
return Field(x);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=base64-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-field.js","sourceRoot":"","sources":["../../../src/utils/base64-field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE/C,+BAA+B;AAC/B,MAAM,KAAK,GACT,kEAAkE,CAAC;AAErE,MAAM,UAAU,aAAa,CAAC,KAAY;IACxC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAC;IAC7C,iCAAiC;IACjC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzD,2BAA2B;IAC3B,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,MAAM,CAAC,GAAG,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;IACtC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAY;IACxC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAC;IAC7C,iCAAiC;IACjC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzD,2BAA2B;IAC3B,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,MAAM,CAAC,GAAG,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;IACtC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function bigintToBase56(value: bigint): string;
|
|
2
|
+
export declare function bigintFromBase56(str: string): bigint;
|
|
3
|
+
export declare function bigintToBase64(value: bigint): string;
|
|
4
|
+
export declare function bigintFromBase64(str: string): bigint;
|
|
5
|
+
export declare function fromBase(digits: bigint[], base: bigint): bigint;
|
|
6
|
+
export declare function toBase(x: bigint, base: bigint): bigint[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// URL friendly base64 encoding
|
|
2
|
+
const TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
3
|
+
export function bigintToBase56(value) {
|
|
4
|
+
const digits = toBase(value, 56n);
|
|
5
|
+
//console.log("digits:", digits);
|
|
6
|
+
const str = digits.map((x) => TABLE[Number(x)]).join("");
|
|
7
|
+
//console.log("str:", str);
|
|
8
|
+
return str;
|
|
9
|
+
}
|
|
10
|
+
export function bigintFromBase56(str) {
|
|
11
|
+
const base56Digits = str.split("").map((x) => BigInt(TABLE.indexOf(x)));
|
|
12
|
+
const x = fromBase(base56Digits, 56n);
|
|
13
|
+
return x;
|
|
14
|
+
}
|
|
15
|
+
export function bigintToBase64(value) {
|
|
16
|
+
const digits = toBase(value, 64n);
|
|
17
|
+
//console.log("digits:", digits);
|
|
18
|
+
const str = digits.map((x) => TABLE[Number(x)]).join("");
|
|
19
|
+
//console.log("str:", str);
|
|
20
|
+
return str;
|
|
21
|
+
}
|
|
22
|
+
export function bigintFromBase64(str) {
|
|
23
|
+
const base64Digits = str.split("").map((x) => BigInt(TABLE.indexOf(x)));
|
|
24
|
+
const x = fromBase(base64Digits, 64n);
|
|
25
|
+
return x;
|
|
26
|
+
}
|
|
27
|
+
export function fromBase(digits, base) {
|
|
28
|
+
if (base <= 0n)
|
|
29
|
+
throw Error("fromBase: base must be positive");
|
|
30
|
+
// compute powers base, base^2, base^4, ..., base^(2^k)
|
|
31
|
+
// with largest k s.t. n = 2^k < digits.length
|
|
32
|
+
let basePowers = [];
|
|
33
|
+
for (let power = base, n = 1; n < digits.length; power **= 2n, n *= 2) {
|
|
34
|
+
basePowers.push(power);
|
|
35
|
+
}
|
|
36
|
+
let k = basePowers.length;
|
|
37
|
+
// pad digits array with zeros s.t. digits.length === 2^k
|
|
38
|
+
digits = digits.concat(Array(2 ** k - digits.length).fill(0n));
|
|
39
|
+
// accumulate [x0, x1, x2, x3, ...] -> [x0 + base*x1, x2 + base*x3, ...] -> [x0 + base*x1 + base^2*(x2 + base*x3), ...] -> ...
|
|
40
|
+
// until we end up with a single element
|
|
41
|
+
for (let i = 0; i < k; i++) {
|
|
42
|
+
let newDigits = Array(digits.length >> 1);
|
|
43
|
+
let basePower = basePowers[i];
|
|
44
|
+
for (let j = 0; j < newDigits.length; j++) {
|
|
45
|
+
newDigits[j] = digits[2 * j] + basePower * digits[2 * j + 1];
|
|
46
|
+
}
|
|
47
|
+
digits = newDigits;
|
|
48
|
+
}
|
|
49
|
+
console.assert(digits.length === 1);
|
|
50
|
+
let [digit] = digits;
|
|
51
|
+
return digit;
|
|
52
|
+
}
|
|
53
|
+
export function toBase(x, base) {
|
|
54
|
+
if (base <= 0n)
|
|
55
|
+
throw Error("toBase: base must be positive");
|
|
56
|
+
// compute powers base, base^2, base^4, ..., base^(2^k)
|
|
57
|
+
// with largest k s.t. base^(2^k) < x
|
|
58
|
+
let basePowers = [];
|
|
59
|
+
for (let power = base; power <= x; power **= 2n) {
|
|
60
|
+
basePowers.push(power);
|
|
61
|
+
}
|
|
62
|
+
let digits = [x]; // single digit w.r.t base^(2^(k+1))
|
|
63
|
+
// successively split digits w.r.t. base^(2^j) into digits w.r.t. base^(2^(j-1))
|
|
64
|
+
// until we arrive at digits w.r.t. base
|
|
65
|
+
let k = basePowers.length;
|
|
66
|
+
for (let i = 0; i < k; i++) {
|
|
67
|
+
let newDigits = Array(2 * digits.length);
|
|
68
|
+
let basePower = basePowers[k - 1 - i];
|
|
69
|
+
for (let j = 0; j < digits.length; j++) {
|
|
70
|
+
let x = digits[j];
|
|
71
|
+
let high = x / basePower;
|
|
72
|
+
newDigits[2 * j + 1] = high;
|
|
73
|
+
newDigits[2 * j] = x - high * basePower;
|
|
74
|
+
}
|
|
75
|
+
digits = newDigits;
|
|
76
|
+
}
|
|
77
|
+
// pop "leading" zero digits
|
|
78
|
+
while (digits[digits.length - 1] === 0n) {
|
|
79
|
+
digits.pop();
|
|
80
|
+
}
|
|
81
|
+
return digits;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../../src/utils/base64.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,MAAM,KAAK,GACT,kEAAkE,CAAC;AAErE,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAClC,iCAAiC;IACjC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzD,2BAA2B;IAC3B,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,MAAM,CAAC,GAAG,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;IACtC,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAClC,iCAAiC;IACjC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC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