zkcloudworker 0.12.2 → 0.14.1
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 +6 -0
- package/lib/ts/src/mina/transactions/index.js +22 -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/tiny-contract.d.ts +5 -0
- package/lib/ts/src/mina/transactions/tiny-contract.js +33 -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 +6 -0
- package/lib/web/src/mina/transactions/index.js +7 -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/tiny-contract.d.ts +5 -0
- package/lib/web/src/mina/transactions/tiny-contract.js +22 -0
- package/lib/web/src/mina/transactions/tiny-contract.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,102 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.FungibleTokenAdmin = void 0;
|
13
|
+
const o1js_1 = require("o1js");
|
14
|
+
/** A contract that grants permissions for administrative actions on a token.
|
15
|
+
*
|
16
|
+
* We separate this out into a dedicated contract. That way, when issuing a token, a user can
|
17
|
+
* specify their own rules for administrative actions, without changing the token contract itself.
|
18
|
+
*
|
19
|
+
* The advantage is that third party applications that only use the token in a non-privileged way
|
20
|
+
* can integrate against the unchanged token contract.
|
21
|
+
*/
|
22
|
+
class FungibleTokenAdmin extends o1js_1.SmartContract {
|
23
|
+
constructor() {
|
24
|
+
super(...arguments);
|
25
|
+
this.adminPublicKey = (0, o1js_1.State)();
|
26
|
+
}
|
27
|
+
async deploy(props) {
|
28
|
+
await super.deploy(props);
|
29
|
+
this.adminPublicKey.set(props.adminPublicKey);
|
30
|
+
this.account.permissions.set({
|
31
|
+
...o1js_1.Permissions.default(),
|
32
|
+
setVerificationKey: o1js_1.Permissions.VerificationKey.impossibleDuringCurrentVersion(),
|
33
|
+
setPermissions: o1js_1.Permissions.impossible(),
|
34
|
+
});
|
35
|
+
}
|
36
|
+
/** Update the verification key.
|
37
|
+
* 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.
|
38
|
+
*/
|
39
|
+
async updateVerificationKey(vk) {
|
40
|
+
this.account.verificationKey.set(vk);
|
41
|
+
}
|
42
|
+
async ensureAdminSignature() {
|
43
|
+
const admin = await o1js_1.Provable.witnessAsync(o1js_1.PublicKey, async () => {
|
44
|
+
let pk = await this.adminPublicKey.fetch();
|
45
|
+
(0, o1js_1.assert)(pk !== undefined, "could not fetch admin public key");
|
46
|
+
return pk;
|
47
|
+
});
|
48
|
+
this.adminPublicKey.requireEquals(admin);
|
49
|
+
return o1js_1.AccountUpdate.createSigned(admin);
|
50
|
+
}
|
51
|
+
async canMint(_accountUpdate) {
|
52
|
+
await this.ensureAdminSignature();
|
53
|
+
return (0, o1js_1.Bool)(true);
|
54
|
+
}
|
55
|
+
async canChangeAdmin(_admin) {
|
56
|
+
await this.ensureAdminSignature();
|
57
|
+
return (0, o1js_1.Bool)(true);
|
58
|
+
}
|
59
|
+
async canPause() {
|
60
|
+
await this.ensureAdminSignature();
|
61
|
+
return (0, o1js_1.Bool)(true);
|
62
|
+
}
|
63
|
+
async canResume() {
|
64
|
+
await this.ensureAdminSignature();
|
65
|
+
return (0, o1js_1.Bool)(true);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
exports.FungibleTokenAdmin = FungibleTokenAdmin;
|
69
|
+
__decorate([
|
70
|
+
(0, o1js_1.state)(o1js_1.PublicKey),
|
71
|
+
__metadata("design:type", Object)
|
72
|
+
], FungibleTokenAdmin.prototype, "adminPublicKey", void 0);
|
73
|
+
__decorate([
|
74
|
+
o1js_1.method,
|
75
|
+
__metadata("design:type", Function),
|
76
|
+
__metadata("design:paramtypes", [o1js_1.VerificationKey]),
|
77
|
+
__metadata("design:returntype", Promise)
|
78
|
+
], FungibleTokenAdmin.prototype, "updateVerificationKey", null);
|
79
|
+
__decorate([
|
80
|
+
o1js_1.method.returns(o1js_1.Bool),
|
81
|
+
__metadata("design:type", Function),
|
82
|
+
__metadata("design:paramtypes", [o1js_1.AccountUpdate]),
|
83
|
+
__metadata("design:returntype", Promise)
|
84
|
+
], FungibleTokenAdmin.prototype, "canMint", null);
|
85
|
+
__decorate([
|
86
|
+
o1js_1.method.returns(o1js_1.Bool),
|
87
|
+
__metadata("design:type", Function),
|
88
|
+
__metadata("design:paramtypes", [o1js_1.PublicKey]),
|
89
|
+
__metadata("design:returntype", Promise)
|
90
|
+
], FungibleTokenAdmin.prototype, "canChangeAdmin", null);
|
91
|
+
__decorate([
|
92
|
+
o1js_1.method.returns(o1js_1.Bool),
|
93
|
+
__metadata("design:type", Function),
|
94
|
+
__metadata("design:paramtypes", []),
|
95
|
+
__metadata("design:returntype", Promise)
|
96
|
+
], FungibleTokenAdmin.prototype, "canPause", null);
|
97
|
+
__decorate([
|
98
|
+
o1js_1.method.returns(o1js_1.Bool),
|
99
|
+
__metadata("design:type", Function),
|
100
|
+
__metadata("design:paramtypes", []),
|
101
|
+
__metadata("design:returntype", Promise)
|
102
|
+
], FungibleTokenAdmin.prototype, "canResume", null);
|
@@ -0,0 +1,18 @@
|
|
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("./FungibleToken"), exports);
|
18
|
+
__exportStar(require("./FungibleTokenAdmin"), exports);
|
@@ -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,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getZkAppTxsFromBlockBerry = getZkAppTxsFromBlockBerry;
|
4
|
+
exports.getPaymentTxsFromBlockBerry = getPaymentTxsFromBlockBerry;
|
5
|
+
exports.getZkAppTxFromBlockBerry = getZkAppTxFromBlockBerry;
|
6
|
+
async function getZkAppTxsFromBlockBerry(params) {
|
7
|
+
const { account, chain, blockBerryApiKey } = params;
|
8
|
+
const options = {
|
9
|
+
method: "GET",
|
10
|
+
headers: {
|
11
|
+
accept: "application/json",
|
12
|
+
"x-api-key": blockBerryApiKey,
|
13
|
+
},
|
14
|
+
};
|
15
|
+
try {
|
16
|
+
const response = await fetch(`https://api.blockberry.one/mina-${chain}/v1/zkapps/accounts/${account}/txs?size=10&orderBy=DESC&sortBy=AGE`, options);
|
17
|
+
if (!response.ok) {
|
18
|
+
console.error("Cannot fetch zkApp txs for account:", account, chain, response.statusText);
|
19
|
+
return undefined;
|
20
|
+
}
|
21
|
+
const result = await response.json();
|
22
|
+
//console.log("zkAppTxs", result);
|
23
|
+
return result;
|
24
|
+
}
|
25
|
+
catch (err) {
|
26
|
+
console.error("Cannot fetch zkApp txs for account - catch:", account, chain, err);
|
27
|
+
return undefined;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
async function getPaymentTxsFromBlockBerry(params) {
|
31
|
+
const { account, chain, blockBerryApiKey } = params;
|
32
|
+
const options = {
|
33
|
+
method: "GET",
|
34
|
+
headers: {
|
35
|
+
accept: "application/json",
|
36
|
+
"x-api-key": blockBerryApiKey,
|
37
|
+
},
|
38
|
+
};
|
39
|
+
try {
|
40
|
+
const response = await fetch(`https://api.blockberry.one/mina-${chain}/v1/accounts/` +
|
41
|
+
account +
|
42
|
+
"/txs?page=0&size=1&orderBy=DESC&sortBy=AGE&direction=OUT", options);
|
43
|
+
if (!response.ok) {
|
44
|
+
console.error("Cannot fetch payment txs for account:", account, chain, response.statusText);
|
45
|
+
return undefined;
|
46
|
+
}
|
47
|
+
const result = await response.json();
|
48
|
+
//console.log("paymentTxs", result);
|
49
|
+
return result;
|
50
|
+
}
|
51
|
+
catch (err) {
|
52
|
+
console.error("Cannot fetch payment txs for account - catch:", account, chain, err);
|
53
|
+
return undefined;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
async function getZkAppTxFromBlockBerry(params) {
|
57
|
+
const { hash, chain, blockBerryApiKey } = params;
|
58
|
+
const options = {
|
59
|
+
method: "GET",
|
60
|
+
headers: {
|
61
|
+
accept: "application/json",
|
62
|
+
"x-api-key": blockBerryApiKey,
|
63
|
+
},
|
64
|
+
};
|
65
|
+
try {
|
66
|
+
const response = await fetch(`https://api.blockberry.one/mina-${chain}/v1/zkapps/txs/${hash}`, options);
|
67
|
+
if (response.ok) {
|
68
|
+
const result = await response.json();
|
69
|
+
return result;
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
console.error("getZkAppTxFromBlockBerry error while getting hash - not ok", { hash, chain, text: response.statusText, status: response.status });
|
73
|
+
return undefined;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
catch (err) {
|
77
|
+
console.error("getZkAppTxFromBlockBerry error while getting mainnet hash - catch", hash, chain, err);
|
78
|
+
return undefined;
|
79
|
+
}
|
80
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export type BlockBerryChain = "mainnet" | "devnet";
|
@@ -0,0 +1,22 @@
|
|
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("./nonce"), exports);
|
18
|
+
__exportStar(require("./transaction"), exports);
|
19
|
+
__exportStar(require("./txstatus"), exports);
|
20
|
+
__exportStar(require("./chain"), exports);
|
21
|
+
__exportStar(require("./blockberry"), exports);
|
22
|
+
__exportStar(require("./tiny-contract"), exports);
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getNonce = getNonce;
|
4
|
+
const blockberry_1 = require("./blockberry");
|
5
|
+
async function getNonce(params) {
|
6
|
+
const { account, chain, blockBerryApiKey } = params;
|
7
|
+
try {
|
8
|
+
if (account === undefined || account === null || account === "") {
|
9
|
+
return {
|
10
|
+
success: false,
|
11
|
+
nonce: -1,
|
12
|
+
message: "Account is required",
|
13
|
+
};
|
14
|
+
}
|
15
|
+
if (blockBerryApiKey === undefined ||
|
16
|
+
blockBerryApiKey === null ||
|
17
|
+
blockBerryApiKey === "") {
|
18
|
+
return {
|
19
|
+
success: false,
|
20
|
+
nonce: -1,
|
21
|
+
message: "blockBerryApiKey is required",
|
22
|
+
};
|
23
|
+
}
|
24
|
+
const zkAppTxsPromise = (0, blockberry_1.getZkAppTxsFromBlockBerry)({
|
25
|
+
account,
|
26
|
+
chain,
|
27
|
+
blockBerryApiKey,
|
28
|
+
});
|
29
|
+
const paymentTxs = (0, blockberry_1.getPaymentTxsFromBlockBerry)({
|
30
|
+
account,
|
31
|
+
chain,
|
32
|
+
blockBerryApiKey,
|
33
|
+
});
|
34
|
+
const paymentNonce = (await paymentTxs)?.data[0]?.nonce ?? -1;
|
35
|
+
let zkNonce = -1;
|
36
|
+
let found = false;
|
37
|
+
const zkAppTxs = await zkAppTxsPromise;
|
38
|
+
const size = zkAppTxs?.data?.length ?? 0;
|
39
|
+
let i = 0;
|
40
|
+
while (!found && i < size) {
|
41
|
+
if (zkAppTxs?.data[i]?.proverAddress === account) {
|
42
|
+
zkNonce = zkAppTxs?.data[i]?.nonce;
|
43
|
+
found = true;
|
44
|
+
}
|
45
|
+
i++;
|
46
|
+
}
|
47
|
+
const nonce = Math.max(zkNonce, paymentNonce);
|
48
|
+
return {
|
49
|
+
success: true,
|
50
|
+
nonce,
|
51
|
+
};
|
52
|
+
}
|
53
|
+
catch (error) {
|
54
|
+
return {
|
55
|
+
success: false,
|
56
|
+
nonce: -1,
|
57
|
+
message: String(error),
|
58
|
+
};
|
59
|
+
}
|
60
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
+
};
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.TinyContract = void 0;
|
13
|
+
const o1js_1 = require("o1js");
|
14
|
+
class TinyContract extends o1js_1.SmartContract {
|
15
|
+
constructor() {
|
16
|
+
super(...arguments);
|
17
|
+
this.value = (0, o1js_1.State)();
|
18
|
+
}
|
19
|
+
async setValue(value) {
|
20
|
+
this.value.set(value);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
exports.TinyContract = TinyContract;
|
24
|
+
__decorate([
|
25
|
+
(0, o1js_1.state)(o1js_1.Field),
|
26
|
+
__metadata("design:type", Object)
|
27
|
+
], TinyContract.prototype, "value", void 0);
|
28
|
+
__decorate([
|
29
|
+
o1js_1.method,
|
30
|
+
__metadata("design:type", Function),
|
31
|
+
__metadata("design:paramtypes", [o1js_1.Field]),
|
32
|
+
__metadata("design:returntype", Promise)
|
33
|
+
], TinyContract.prototype, "setValue", null);
|
@@ -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,69 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.transactionParams = transactionParams;
|
4
|
+
exports.deserializeTransaction = deserializeTransaction;
|
5
|
+
exports.serializeTransaction = serializeTransaction;
|
6
|
+
const o1js_1 = require("o1js");
|
7
|
+
function transactionParams(serializedTransaction, signedJson) {
|
8
|
+
const { sender, nonce, tx } = JSON.parse(serializedTransaction);
|
9
|
+
const transaction = o1js_1.Mina.Transaction.fromJSON(JSON.parse(tx));
|
10
|
+
const memo = transaction.transaction.memo;
|
11
|
+
return {
|
12
|
+
fee: o1js_1.UInt64.from(signedJson.zkappCommand.feePayer.body.fee),
|
13
|
+
sender: o1js_1.PublicKey.fromBase58(sender),
|
14
|
+
nonce: Number(signedJson.zkappCommand.feePayer.body.nonce),
|
15
|
+
memo,
|
16
|
+
};
|
17
|
+
}
|
18
|
+
function deserializeTransaction(serializedTransaction, txNew, signedJson) {
|
19
|
+
//console.log("new transaction", txNew);
|
20
|
+
const { tx, blindingValues, length } = JSON.parse(serializedTransaction);
|
21
|
+
const transaction = o1js_1.Mina.Transaction.fromJSON(JSON.parse(tx));
|
22
|
+
//console.log("transaction", transaction);
|
23
|
+
if (length !== txNew.transaction.accountUpdates.length) {
|
24
|
+
throw new Error("New Transaction length mismatch");
|
25
|
+
}
|
26
|
+
if (length !== transaction.transaction.accountUpdates.length) {
|
27
|
+
throw new Error("Serialized Transaction length mismatch");
|
28
|
+
}
|
29
|
+
for (let i = 0; i < length; i++) {
|
30
|
+
transaction.transaction.accountUpdates[i].lazyAuthorization =
|
31
|
+
txNew.transaction.accountUpdates[i].lazyAuthorization;
|
32
|
+
if (blindingValues[i] !== "")
|
33
|
+
transaction.transaction.accountUpdates[i].lazyAuthorization.blindingValue = o1js_1.Field.fromJSON(blindingValues[i]);
|
34
|
+
}
|
35
|
+
transaction.transaction.feePayer.authorization =
|
36
|
+
signedJson.zkappCommand.feePayer.authorization;
|
37
|
+
transaction.transaction.feePayer.body.fee = o1js_1.UInt64.from(signedJson.zkappCommand.feePayer.body.fee);
|
38
|
+
for (let i = 0; i < length; i++) {
|
39
|
+
const signature = signedJson.zkappCommand.accountUpdates[i].authorization.signature;
|
40
|
+
if (signature !== undefined && signature !== null) {
|
41
|
+
transaction.transaction.accountUpdates[i].authorization.signature =
|
42
|
+
signedJson.zkappCommand.accountUpdates[i].authorization.signature;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
return transaction;
|
46
|
+
}
|
47
|
+
function serializeTransaction(tx) {
|
48
|
+
const length = tx.transaction.accountUpdates.length;
|
49
|
+
let i;
|
50
|
+
let blindingValues = [];
|
51
|
+
for (i = 0; i < length; i++) {
|
52
|
+
const la = tx.transaction.accountUpdates[i].lazyAuthorization;
|
53
|
+
if (la !== undefined &&
|
54
|
+
la.blindingValue !== undefined &&
|
55
|
+
la.kind === "lazy-proof")
|
56
|
+
blindingValues.push(la.blindingValue.toJSON());
|
57
|
+
else
|
58
|
+
blindingValues.push("");
|
59
|
+
}
|
60
|
+
const serializedTransaction = JSON.stringify({
|
61
|
+
tx: tx.toJSON(),
|
62
|
+
blindingValues,
|
63
|
+
length,
|
64
|
+
fee: tx.transaction.feePayer.body.fee.toJSON(),
|
65
|
+
sender: tx.transaction.feePayer.body.publicKey.toBase58(),
|
66
|
+
nonce: tx.transaction.feePayer.body.nonce.toBigint().toString(),
|
67
|
+
}, null, 2);
|
68
|
+
return serializedTransaction;
|
69
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.txStatus = txStatus;
|
4
|
+
const blockberry_1 = require("./blockberry");
|
5
|
+
const TIMEOUT = 1000 * 60 * 21;
|
6
|
+
async function txStatus(params) {
|
7
|
+
const { hash, chain, time, blockBerryApiKey } = params;
|
8
|
+
const tx = await (0, blockberry_1.getZkAppTxFromBlockBerry)({ hash, chain, blockBerryApiKey });
|
9
|
+
if (tx?.txStatus)
|
10
|
+
return tx?.txStatus;
|
11
|
+
if (Date.now() - time > (params.timeout ?? TIMEOUT)) {
|
12
|
+
console.error("txStatus: Timeout while checking tx with blockberry", chain, hash);
|
13
|
+
return "replaced";
|
14
|
+
}
|
15
|
+
else {
|
16
|
+
return "pending";
|
17
|
+
}
|
18
|
+
}
|