zkcloudworker 0.12.2 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/ts/src/mina/index.d.ts +2 -0
- package/lib/ts/src/mina/index.js +2 -0
- package/lib/ts/src/mina/token/FungibleToken.d.ts +338 -0
- package/lib/ts/src/mina/token/FungibleToken.js +290 -0
- package/lib/ts/src/mina/token/FungibleTokenAdmin.d.ts +31 -0
- package/lib/ts/src/mina/token/FungibleTokenAdmin.js +102 -0
- package/lib/ts/src/mina/token/index.d.ts +2 -0
- package/lib/ts/src/mina/token/index.js +18 -0
- package/lib/ts/src/mina/transactions/blockberry.d.ts +16 -0
- package/lib/ts/src/mina/transactions/blockberry.js +80 -0
- package/lib/ts/src/mina/transactions/chain.d.ts +1 -0
- package/lib/ts/src/mina/transactions/chain.js +2 -0
- package/lib/ts/src/mina/transactions/index.d.ts +5 -0
- package/lib/ts/src/mina/transactions/index.js +21 -0
- package/lib/ts/src/mina/transactions/nonce.d.ts +10 -0
- package/lib/ts/src/mina/transactions/nonce.js +60 -0
- package/lib/ts/src/mina/transactions/transaction.d.ts +9 -0
- package/lib/ts/src/mina/transactions/transaction.js +69 -0
- package/lib/ts/src/mina/transactions/txstatus.d.ts +8 -0
- package/lib/ts/src/mina/transactions/txstatus.js +18 -0
- package/lib/ts/src/mina/utils/fetch.js +1 -1
- package/lib/ts/tsconfig.tsbuildinfo +1 -1
- package/lib/web/src/mina/index.d.ts +2 -0
- package/lib/web/src/mina/index.js +2 -0
- package/lib/web/src/mina/index.js.map +1 -1
- package/lib/web/src/mina/token/FungibleToken.d.ts +338 -0
- package/lib/web/src/mina/token/FungibleToken.js +274 -0
- package/lib/web/src/mina/token/FungibleToken.js.map +1 -0
- package/lib/web/src/mina/token/FungibleTokenAdmin.d.ts +31 -0
- package/lib/web/src/mina/token/FungibleTokenAdmin.js +91 -0
- package/lib/web/src/mina/token/FungibleTokenAdmin.js.map +1 -0
- package/lib/web/src/mina/token/index.d.ts +2 -0
- package/lib/web/src/mina/token/index.js +3 -0
- package/lib/web/src/mina/token/index.js.map +1 -0
- package/lib/web/src/mina/transactions/blockberry.d.ts +16 -0
- package/lib/web/src/mina/transactions/blockberry.js +76 -0
- package/lib/web/src/mina/transactions/blockberry.js.map +1 -0
- package/lib/web/src/mina/transactions/chain.d.ts +1 -0
- package/lib/web/src/mina/transactions/chain.js +2 -0
- package/lib/web/src/mina/transactions/chain.js.map +1 -0
- package/lib/web/src/mina/transactions/index.d.ts +5 -0
- package/lib/web/src/mina/transactions/index.js +6 -0
- package/lib/web/src/mina/transactions/index.js.map +1 -0
- package/lib/web/src/mina/transactions/nonce.d.ts +10 -0
- package/lib/web/src/mina/transactions/nonce.js +58 -0
- package/lib/web/src/mina/transactions/nonce.js.map +1 -0
- package/lib/web/src/mina/transactions/transaction.d.ts +9 -0
- package/lib/web/src/mina/transactions/transaction.js +65 -0
- package/lib/web/src/mina/transactions/transaction.js.map +1 -0
- package/lib/web/src/mina/transactions/txstatus.d.ts +8 -0
- package/lib/web/src/mina/transactions/txstatus.js +16 -0
- package/lib/web/src/mina/transactions/txstatus.js.map +1 -0
- package/lib/web/src/mina/utils/fetch.js +1 -1
- package/lib/web/tsconfig.web.tsbuildinfo +1 -1
- package/package.json +5 -5
@@ -0,0 +1,91 @@
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
2
|
+
import { AccountUpdate, assert, Bool, method, Permissions, Provable, PublicKey, SmartContract, State, state, VerificationKey, } from "o1js";
|
3
|
+
/** A contract that grants permissions for administrative actions on a token.
|
4
|
+
*
|
5
|
+
* We separate this out into a dedicated contract. That way, when issuing a token, a user can
|
6
|
+
* specify their own rules for administrative actions, without changing the token contract itself.
|
7
|
+
*
|
8
|
+
* The advantage is that third party applications that only use the token in a non-privileged way
|
9
|
+
* can integrate against the unchanged token contract.
|
10
|
+
*/
|
11
|
+
export class FungibleTokenAdmin extends SmartContract {
|
12
|
+
constructor() {
|
13
|
+
super(...arguments);
|
14
|
+
this.adminPublicKey = State();
|
15
|
+
}
|
16
|
+
async deploy(props) {
|
17
|
+
await super.deploy(props);
|
18
|
+
this.adminPublicKey.set(props.adminPublicKey);
|
19
|
+
this.account.permissions.set({
|
20
|
+
...Permissions.default(),
|
21
|
+
setVerificationKey: Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
22
|
+
setPermissions: Permissions.impossible(),
|
23
|
+
});
|
24
|
+
}
|
25
|
+
/** Update the verification key.
|
26
|
+
* Note that because we have set the permissions for setting the verification key to `impossibleDuringCurrentVersion()`, this will only be possible in case of a protocol update that requires an update.
|
27
|
+
*/
|
28
|
+
async updateVerificationKey(vk) {
|
29
|
+
this.account.verificationKey.set(vk);
|
30
|
+
}
|
31
|
+
async ensureAdminSignature() {
|
32
|
+
const admin = await Provable.witnessAsync(PublicKey, async () => {
|
33
|
+
let pk = await this.adminPublicKey.fetch();
|
34
|
+
assert(pk !== undefined, "could not fetch admin public key");
|
35
|
+
return pk;
|
36
|
+
});
|
37
|
+
this.adminPublicKey.requireEquals(admin);
|
38
|
+
return AccountUpdate.createSigned(admin);
|
39
|
+
}
|
40
|
+
async canMint(_accountUpdate) {
|
41
|
+
await this.ensureAdminSignature();
|
42
|
+
return Bool(true);
|
43
|
+
}
|
44
|
+
async canChangeAdmin(_admin) {
|
45
|
+
await this.ensureAdminSignature();
|
46
|
+
return Bool(true);
|
47
|
+
}
|
48
|
+
async canPause() {
|
49
|
+
await this.ensureAdminSignature();
|
50
|
+
return Bool(true);
|
51
|
+
}
|
52
|
+
async canResume() {
|
53
|
+
await this.ensureAdminSignature();
|
54
|
+
return Bool(true);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
__decorate([
|
58
|
+
state(PublicKey),
|
59
|
+
__metadata("design:type", Object)
|
60
|
+
], FungibleTokenAdmin.prototype, "adminPublicKey", void 0);
|
61
|
+
__decorate([
|
62
|
+
method,
|
63
|
+
__metadata("design:type", Function),
|
64
|
+
__metadata("design:paramtypes", [VerificationKey]),
|
65
|
+
__metadata("design:returntype", Promise)
|
66
|
+
], FungibleTokenAdmin.prototype, "updateVerificationKey", null);
|
67
|
+
__decorate([
|
68
|
+
method.returns(Bool),
|
69
|
+
__metadata("design:type", Function),
|
70
|
+
__metadata("design:paramtypes", [AccountUpdate]),
|
71
|
+
__metadata("design:returntype", Promise)
|
72
|
+
], FungibleTokenAdmin.prototype, "canMint", null);
|
73
|
+
__decorate([
|
74
|
+
method.returns(Bool),
|
75
|
+
__metadata("design:type", Function),
|
76
|
+
__metadata("design:paramtypes", [PublicKey]),
|
77
|
+
__metadata("design:returntype", Promise)
|
78
|
+
], FungibleTokenAdmin.prototype, "canChangeAdmin", null);
|
79
|
+
__decorate([
|
80
|
+
method.returns(Bool),
|
81
|
+
__metadata("design:type", Function),
|
82
|
+
__metadata("design:paramtypes", []),
|
83
|
+
__metadata("design:returntype", Promise)
|
84
|
+
], FungibleTokenAdmin.prototype, "canPause", null);
|
85
|
+
__decorate([
|
86
|
+
method.returns(Bool),
|
87
|
+
__metadata("design:type", Function),
|
88
|
+
__metadata("design:paramtypes", []),
|
89
|
+
__metadata("design:returntype", Promise)
|
90
|
+
], FungibleTokenAdmin.prototype, "canResume", null);
|
91
|
+
//# sourceMappingURL=FungibleTokenAdmin.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"FungibleTokenAdmin.js","sourceRoot":"","sources":["../../../../../../src/mina/token/FungibleTokenAdmin.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,MAAM,EACN,IAAI,EAEJ,MAAM,EACN,WAAW,EACX,QAAQ,EACR,SAAS,EACT,aAAa,EACb,KAAK,EACL,KAAK,EACL,eAAe,GAChB,MAAM,MAAM,CAAA;AAab;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAmB,SAAQ,aAAa;IAArD;;QAEU,mBAAc,GAAG,KAAK,EAAa,CAAA;IAqD7C,CAAC;IAnDC,KAAK,CAAC,MAAM,CAAC,KAAoC;QAC/C,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAA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OAAO,IAAI,CAAC,IAAI,CAAC,CAAA;IACnB,CAAC;IAGY,AAAN,KAAK,CAAC,SAAS;QACpB,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAA;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAA;IACnB,CAAC;CACF;AArDS;IADP,KAAK,CAAC,SAAS,CAAC;;0DAC0B;AAgBrC;IADL,MAAM;;qCACyB,eAAe;;+DAE9C;AAaY;IADZ,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;;qCACgB,aAAa;;iDAGjD;AAGY;IADZ,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;;qCACe,SAAS;;wDAG5C;AAGY;IADZ,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;;;;kDAIpB;AAGY;IADZ,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;;;;mDAIpB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/mina/token/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { BlockBerryChain } from "./chain";
|
2
|
+
export declare function getZkAppTxsFromBlockBerry(params: {
|
3
|
+
account: string;
|
4
|
+
chain: BlockBerryChain;
|
5
|
+
blockBerryApiKey: string;
|
6
|
+
}): Promise<any>;
|
7
|
+
export declare function getPaymentTxsFromBlockBerry(params: {
|
8
|
+
account: string;
|
9
|
+
chain: BlockBerryChain;
|
10
|
+
blockBerryApiKey: string;
|
11
|
+
}): Promise<any>;
|
12
|
+
export declare function getZkAppTxFromBlockBerry(params: {
|
13
|
+
hash: string;
|
14
|
+
chain: BlockBerryChain;
|
15
|
+
blockBerryApiKey: string;
|
16
|
+
}): Promise<any>;
|
@@ -0,0 +1,76 @@
|
|
1
|
+
export async function getZkAppTxsFromBlockBerry(params) {
|
2
|
+
const { account, chain, blockBerryApiKey } = params;
|
3
|
+
const options = {
|
4
|
+
method: "GET",
|
5
|
+
headers: {
|
6
|
+
accept: "application/json",
|
7
|
+
"x-api-key": blockBerryApiKey,
|
8
|
+
},
|
9
|
+
};
|
10
|
+
try {
|
11
|
+
const response = await fetch(`https://api.blockberry.one/mina-${chain}/v1/zkapps/accounts/${account}/txs?size=10&orderBy=DESC&sortBy=AGE`, options);
|
12
|
+
if (!response.ok) {
|
13
|
+
console.error("Cannot fetch zkApp txs for account:", account, chain, response.statusText);
|
14
|
+
return undefined;
|
15
|
+
}
|
16
|
+
const result = await response.json();
|
17
|
+
//console.log("zkAppTxs", result);
|
18
|
+
return result;
|
19
|
+
}
|
20
|
+
catch (err) {
|
21
|
+
console.error("Cannot fetch zkApp txs for account - catch:", account, chain, err);
|
22
|
+
return undefined;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
export async function getPaymentTxsFromBlockBerry(params) {
|
26
|
+
const { account, chain, blockBerryApiKey } = params;
|
27
|
+
const options = {
|
28
|
+
method: "GET",
|
29
|
+
headers: {
|
30
|
+
accept: "application/json",
|
31
|
+
"x-api-key": blockBerryApiKey,
|
32
|
+
},
|
33
|
+
};
|
34
|
+
try {
|
35
|
+
const response = await fetch(`https://api.blockberry.one/mina-${chain}/v1/accounts/` +
|
36
|
+
account +
|
37
|
+
"/txs?page=0&size=1&orderBy=DESC&sortBy=AGE&direction=OUT", options);
|
38
|
+
if (!response.ok) {
|
39
|
+
console.error("Cannot fetch payment txs for account:", account, chain, response.statusText);
|
40
|
+
return undefined;
|
41
|
+
}
|
42
|
+
const result = await response.json();
|
43
|
+
//console.log("paymentTxs", result);
|
44
|
+
return result;
|
45
|
+
}
|
46
|
+
catch (err) {
|
47
|
+
console.error("Cannot fetch payment txs for account - catch:", account, chain, err);
|
48
|
+
return undefined;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
export async function getZkAppTxFromBlockBerry(params) {
|
52
|
+
const { hash, chain, blockBerryApiKey } = params;
|
53
|
+
const options = {
|
54
|
+
method: "GET",
|
55
|
+
headers: {
|
56
|
+
accept: "application/json",
|
57
|
+
"x-api-key": blockBerryApiKey,
|
58
|
+
},
|
59
|
+
};
|
60
|
+
try {
|
61
|
+
const response = await fetch(`https://api.blockberry.one/mina-${chain}/v1/zkapps/txs/${hash}`, options);
|
62
|
+
if (response.ok) {
|
63
|
+
const result = await response.json();
|
64
|
+
return result;
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
console.error("getZkAppTxFromBlockBerry error while getting hash - not ok", { hash, chain, text: response.statusText, status: response.status });
|
68
|
+
return undefined;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
catch (err) {
|
72
|
+
console.error("getZkAppTxFromBlockBerry error while getting mainnet hash - catch", hash, chain, err);
|
73
|
+
return undefined;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
//# sourceMappingURL=blockberry.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"blockberry.js","sourceRoot":"","sources":["../../../../../../src/mina/transactions/blockberry.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,MAI/C;IACC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;IACpD,MAAM,OAAO,GAAG;QACd,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,MAAM,EAAE,kBAAkB;YAC1B,WAAW,EAAE,gBAAgB;SAC9B;KACF,CAAC;IACF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,mCAAmC,KAAK,uBAAuB,OAAO,sCAAsC,EAC5G,OAAO,CACR,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,OAAO,CAAC,KAAK,CACX,qCAAqC,EACrC,OAAO,EACP,KAAK,EACL,QAAQ,CAAC,UAAU,CACpB,CAAC;YACF,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAA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,KAAK;QACb,OAAO,EAAE;YACP,MAAM,EAAE,kBAAkB;YAC1B,WAAW,EAAE,gBAAgB;SAC9B;KACF,CAAC;IACF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,mCAAmC,KAAK,kBAAkB,IAAI,EAAE,EAChE,OAAO,CACR,CAAC;QACF,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;YAChB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACrC,OAAO,MAAM,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CACX,4DAA4D,EAC5D,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CACpE,CAAC;YACF,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CACX,mEAAmE,EACnE,IAAI,EACJ,KAAK,EACL,GAAG,CACJ,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export type BlockBerryChain = "mainnet" | "devnet";
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../../../../src/mina/transactions/chain.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/mina/transactions/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { getZkAppTxsFromBlockBerry, getPaymentTxsFromBlockBerry, } from "./blockberry";
|
2
|
+
export async function getNonce(params) {
|
3
|
+
const { account, chain, blockBerryApiKey } = params;
|
4
|
+
try {
|
5
|
+
if (account === undefined || account === null || account === "") {
|
6
|
+
return {
|
7
|
+
success: false,
|
8
|
+
nonce: -1,
|
9
|
+
message: "Account is required",
|
10
|
+
};
|
11
|
+
}
|
12
|
+
if (blockBerryApiKey === undefined ||
|
13
|
+
blockBerryApiKey === null ||
|
14
|
+
blockBerryApiKey === "") {
|
15
|
+
return {
|
16
|
+
success: false,
|
17
|
+
nonce: -1,
|
18
|
+
message: "blockBerryApiKey is required",
|
19
|
+
};
|
20
|
+
}
|
21
|
+
const zkAppTxsPromise = getZkAppTxsFromBlockBerry({
|
22
|
+
account,
|
23
|
+
chain,
|
24
|
+
blockBerryApiKey,
|
25
|
+
});
|
26
|
+
const paymentTxs = getPaymentTxsFromBlockBerry({
|
27
|
+
account,
|
28
|
+
chain,
|
29
|
+
blockBerryApiKey,
|
30
|
+
});
|
31
|
+
const paymentNonce = (await paymentTxs)?.data[0]?.nonce ?? -1;
|
32
|
+
let zkNonce = -1;
|
33
|
+
let found = false;
|
34
|
+
const zkAppTxs = await zkAppTxsPromise;
|
35
|
+
const size = zkAppTxs?.data?.length ?? 0;
|
36
|
+
let i = 0;
|
37
|
+
while (!found && i < size) {
|
38
|
+
if (zkAppTxs?.data[i]?.proverAddress === account) {
|
39
|
+
zkNonce = zkAppTxs?.data[i]?.nonce;
|
40
|
+
found = true;
|
41
|
+
}
|
42
|
+
i++;
|
43
|
+
}
|
44
|
+
const nonce = Math.max(zkNonce, paymentNonce);
|
45
|
+
return {
|
46
|
+
success: true,
|
47
|
+
nonce,
|
48
|
+
};
|
49
|
+
}
|
50
|
+
catch (error) {
|
51
|
+
return {
|
52
|
+
success: false,
|
53
|
+
nonce: -1,
|
54
|
+
message: String(error),
|
55
|
+
};
|
56
|
+
}
|
57
|
+
}
|
58
|
+
//# sourceMappingURL=nonce.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"nonce.js","sour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K,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;YAC1B,IAAI,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,aAAa,KAAK,OAAO,EAAE,CAAC;gBACjD,OAAO,GAAG,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;gBACnC,KAAK,GAAG,IAAI,CAAC;YACf,CAAC;YACD,CAAC,EAAE,CAAC;QACN,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAE9C,OAAO;YACL,OAAO,EAAE,IAAI;YACb,KAAK;SACN,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,CAAC,CAAC;YACT,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;SACvB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { PublicKey, Transaction, Mina, UInt64 } from "o1js";
|
2
|
+
export declare function transactionParams(serializedTransaction: string, signedJson: any): {
|
3
|
+
fee: UInt64;
|
4
|
+
sender: PublicKey;
|
5
|
+
nonce: number;
|
6
|
+
memo: string;
|
7
|
+
};
|
8
|
+
export declare function deserializeTransaction(serializedTransaction: string, txNew: Mina.Transaction<false, false>, signedJson: any): Transaction<false, true>;
|
9
|
+
export declare function serializeTransaction(tx: Mina.Transaction<false, false>): string;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { Field, PublicKey, Mina, UInt64 } from "o1js";
|
2
|
+
export function transactionParams(serializedTransaction, signedJson) {
|
3
|
+
const { sender, nonce, tx } = JSON.parse(serializedTransaction);
|
4
|
+
const transaction = Mina.Transaction.fromJSON(JSON.parse(tx));
|
5
|
+
const memo = transaction.transaction.memo;
|
6
|
+
return {
|
7
|
+
fee: UInt64.from(signedJson.zkappCommand.feePayer.body.fee),
|
8
|
+
sender: PublicKey.fromBase58(sender),
|
9
|
+
nonce: Number(signedJson.zkappCommand.feePayer.body.nonce),
|
10
|
+
memo,
|
11
|
+
};
|
12
|
+
}
|
13
|
+
export function deserializeTransaction(serializedTransaction, txNew, signedJson) {
|
14
|
+
//console.log("new transaction", txNew);
|
15
|
+
const { tx, blindingValues, length } = JSON.parse(serializedTransaction);
|
16
|
+
const transaction = Mina.Transaction.fromJSON(JSON.parse(tx));
|
17
|
+
//console.log("transaction", transaction);
|
18
|
+
if (length !== txNew.transaction.accountUpdates.length) {
|
19
|
+
throw new Error("New Transaction length mismatch");
|
20
|
+
}
|
21
|
+
if (length !== transaction.transaction.accountUpdates.length) {
|
22
|
+
throw new Error("Serialized Transaction length mismatch");
|
23
|
+
}
|
24
|
+
for (let i = 0; i < length; i++) {
|
25
|
+
transaction.transaction.accountUpdates[i].lazyAuthorization =
|
26
|
+
txNew.transaction.accountUpdates[i].lazyAuthorization;
|
27
|
+
if (blindingValues[i] !== "")
|
28
|
+
transaction.transaction.accountUpdates[i].lazyAuthorization.blindingValue = Field.fromJSON(blindingValues[i]);
|
29
|
+
}
|
30
|
+
transaction.transaction.feePayer.authorization =
|
31
|
+
signedJson.zkappCommand.feePayer.authorization;
|
32
|
+
transaction.transaction.feePayer.body.fee = UInt64.from(signedJson.zkappCommand.feePayer.body.fee);
|
33
|
+
for (let i = 0; i < length; i++) {
|
34
|
+
const signature = signedJson.zkappCommand.accountUpdates[i].authorization.signature;
|
35
|
+
if (signature !== undefined && signature !== null) {
|
36
|
+
transaction.transaction.accountUpdates[i].authorization.signature =
|
37
|
+
signedJson.zkappCommand.accountUpdates[i].authorization.signature;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
return transaction;
|
41
|
+
}
|
42
|
+
export function serializeTransaction(tx) {
|
43
|
+
const length = tx.transaction.accountUpdates.length;
|
44
|
+
let i;
|
45
|
+
let blindingValues = [];
|
46
|
+
for (i = 0; i < length; i++) {
|
47
|
+
const la = tx.transaction.accountUpdates[i].lazyAuthorization;
|
48
|
+
if (la !== undefined &&
|
49
|
+
la.blindingValue !== undefined &&
|
50
|
+
la.kind === "lazy-proof")
|
51
|
+
blindingValues.push(la.blindingValue.toJSON());
|
52
|
+
else
|
53
|
+
blindingValues.push("");
|
54
|
+
}
|
55
|
+
const serializedTransaction = JSON.stringify({
|
56
|
+
tx: tx.toJSON(),
|
57
|
+
blindingValues,
|
58
|
+
length,
|
59
|
+
fee: tx.transaction.feePayer.body.fee.toJSON(),
|
60
|
+
sender: tx.transaction.feePayer.body.publicKey.toBase58(),
|
61
|
+
nonce: tx.transaction.feePayer.body.nonce.toBigint().toString(),
|
62
|
+
}, null, 2);
|
63
|
+
return serializedTransaction;
|
64
|
+
}
|
65
|
+
//# sourceMappingURL=transaction.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../../../../src/mina/transactions/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAe,IAAI,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnE,MAAM,UAAU,iBAAiB,CAC/B,qBAA6B,EAC7B,UAAe;IAOf,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC;IAC1C,OAAO;QACL,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;QAC3D,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC;QACpC,KAAK,EAAE,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC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AC,SAAS,CAC1C;QACE,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE;QACf,cAAc;QACd,MAAM;QACN,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;QAC9C,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;QACzD,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;KAChE,EACD,IAAI,EACJ,CAAC,CACF,CAAC;IACF,OAAO,qBAAqB,CAAC;AAC/B,CAAC"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { getZkAppTxFromBlockBerry } from "./blockberry";
|
2
|
+
const TIMEOUT = 1000 * 60 * 21;
|
3
|
+
export async function txStatus(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/mina/transactions/txstatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;AAE/B,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,MAM9B;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"}
|