@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 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,MAAM,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AAC;oBACH,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,MAAM,CACtB,CAAC,QAAQ,EAAE,wCAAwC;gBACpD,GAAG,EAAE,GAAG,iBAAiB,CACvB,UAAU,CAAC,GAAG,CACf,gDAAgD;gBACjD,SAAS,EAAE,GAAG,iBAAiB,CAC7B,UAAU,CAAC,SAAS,CACrB,sCAAsC;gBACvC,QAAQ,EAAE,GAAG,iBAAiB,CAC5B,UAAU,CAAC,QAAQ,CACpB,6CAA6C;gBAC9C,QAAQ,EAAE,GAAG,iBAAiB,CAC5B,UAAU,CAAC,QAAQ,CACpB,wBAAwB;aAC1B;YACH,CAAC,CAAC,cAAc,WAAW,KAAK,iBAAiB,CAAC,UAAU,CAAC,GAAG,CAAC,GAC7D,MAAM,KAAK,CAAC;gBACV,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,eAAe,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,QAAQ,EAAE,GAAG,KAC3D,EAAE,CAAC;QAEP,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@silvana-one/mina-utils",
|
|
3
|
+
"description": "Silvana Mina Utils",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"author": "DFST",
|
|
6
|
+
"bugs": "https://github.com/SilvanaOne/silvana-lib/issues",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"tslib": "^2.8.1"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@types/node": "^22.13.8",
|
|
12
|
+
"esbuild": "^0.25.0",
|
|
13
|
+
"o1js": "^2.2.0",
|
|
14
|
+
"ts-node": "^10.9.2",
|
|
15
|
+
"typescript": "^5.8.2"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=20.0.0"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
"types": "./dist/node/index.d.ts",
|
|
22
|
+
"node": {
|
|
23
|
+
"import": "./dist/node/index.js",
|
|
24
|
+
"require": "./dist/node/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"browser": "./dist/web/index.js",
|
|
27
|
+
"default": "./dist/web/index.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"src",
|
|
32
|
+
"package.json",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"homepage": "https://docs.silvana.one",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"cloud",
|
|
39
|
+
"fungible-token",
|
|
40
|
+
"mina-protocol",
|
|
41
|
+
"silvana-one",
|
|
42
|
+
"proving",
|
|
43
|
+
"tokens",
|
|
44
|
+
"typescript",
|
|
45
|
+
"zkcloudworker"
|
|
46
|
+
],
|
|
47
|
+
"license": "Apache-2.0",
|
|
48
|
+
"main": "dist/web/index.js",
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"o1js": "^2.2.0"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"repository": "SilvanaOne/silvana-lib.git",
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "rm -rf dist && tsc && tsc --build tsconfig.web.json && node build-cjs.js",
|
|
58
|
+
"release": "npm publish --access public"
|
|
59
|
+
},
|
|
60
|
+
"type": "module",
|
|
61
|
+
"types": "./dist/node/index.d.ts"
|
|
62
|
+
}
|
package/src/config.ts
ADDED
package/src/index.ts
ADDED
package/src/networks.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export {
|
|
2
|
+
blockchain,
|
|
3
|
+
MinaNetwork,
|
|
4
|
+
networks,
|
|
5
|
+
Mainnet,
|
|
6
|
+
Devnet,
|
|
7
|
+
Zeko,
|
|
8
|
+
Lightnet,
|
|
9
|
+
Local,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* blockchain is the type for the chain ID.
|
|
14
|
+
*/
|
|
15
|
+
type blockchain = "local" | "devnet" | "lightnet" | "mainnet" | "zeko";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* MinaNetwork is the data structure for a Mina network, keeping track of the Mina and archive endpoints, chain ID, name, account manager, explorer account URL, explorer transaction URL, and faucet.
|
|
19
|
+
*/
|
|
20
|
+
interface MinaNetwork {
|
|
21
|
+
/** The Mina endpoints */
|
|
22
|
+
mina: string[];
|
|
23
|
+
|
|
24
|
+
/** The archive endpoints */
|
|
25
|
+
archive: string[];
|
|
26
|
+
|
|
27
|
+
/** The chain ID */
|
|
28
|
+
chainId: blockchain;
|
|
29
|
+
|
|
30
|
+
/** The name of the network (optional) */
|
|
31
|
+
name?: string;
|
|
32
|
+
|
|
33
|
+
/** The account manager for Lightnet (optional) */
|
|
34
|
+
accountManager?: string;
|
|
35
|
+
|
|
36
|
+
/** The explorer account URL (optional) */
|
|
37
|
+
explorerAccountUrl?: string;
|
|
38
|
+
|
|
39
|
+
/** The explorer transaction URL (optional) */
|
|
40
|
+
explorerTransactionUrl?: string;
|
|
41
|
+
|
|
42
|
+
/** The faucet URL (optional) */
|
|
43
|
+
faucet?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const Mainnet: MinaNetwork = {
|
|
47
|
+
mina: [
|
|
48
|
+
//"https://proxy.devnet.minaexplorer.com/graphql",
|
|
49
|
+
"https://api.minascan.io/node/mainnet/v1/graphql",
|
|
50
|
+
],
|
|
51
|
+
archive: [
|
|
52
|
+
"https://api.minascan.io/archive/mainnet/v1/graphql",
|
|
53
|
+
//"https://archive.devnet.minaexplorer.com",
|
|
54
|
+
],
|
|
55
|
+
explorerAccountUrl: "https://minascan.io/mainnet/account/",
|
|
56
|
+
explorerTransactionUrl: "https://minascan.io/mainnet/tx/",
|
|
57
|
+
chainId: "mainnet",
|
|
58
|
+
name: "Mainnet",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const Local: MinaNetwork = {
|
|
62
|
+
mina: [],
|
|
63
|
+
archive: [],
|
|
64
|
+
chainId: "local",
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const Devnet: MinaNetwork = {
|
|
68
|
+
mina: [
|
|
69
|
+
"https://api.minascan.io/node/devnet/v1/graphql",
|
|
70
|
+
//"https://proxy.devnet.minaexplorer.com/graphql",
|
|
71
|
+
],
|
|
72
|
+
archive: [
|
|
73
|
+
"https://api.minascan.io/archive/devnet/v1/graphql",
|
|
74
|
+
//"https://archive.devnet.minaexplorer.com",
|
|
75
|
+
],
|
|
76
|
+
explorerAccountUrl: "https://minascan.io/devnet/account/",
|
|
77
|
+
explorerTransactionUrl: "https://minascan.io/devnet/tx/",
|
|
78
|
+
chainId: "devnet",
|
|
79
|
+
name: "Devnet",
|
|
80
|
+
faucet: "https://faucet.minaprotocol.com",
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const Zeko: MinaNetwork = {
|
|
84
|
+
mina: ["https://devnet.zeko.io/graphql"],
|
|
85
|
+
archive: ["https://devnet.zeko.io/graphql"],
|
|
86
|
+
explorerAccountUrl: "https://zekoscan.io/devnet/account/",
|
|
87
|
+
explorerTransactionUrl: "https://zekoscan.io/devnet/tx/",
|
|
88
|
+
chainId: "zeko",
|
|
89
|
+
name: "Zeko",
|
|
90
|
+
faucet: "https://zeko.io/faucet",
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const Lightnet: MinaNetwork = {
|
|
94
|
+
mina: ["http://localhost:8080/graphql"],
|
|
95
|
+
archive: ["http://localhost:8282"],
|
|
96
|
+
accountManager: "http://localhost:8181",
|
|
97
|
+
chainId: "lightnet",
|
|
98
|
+
name: "Lightnet",
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const networks: MinaNetwork[] = [Mainnet, Local, Devnet, Zeko, Lightnet];
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
// not supported by o1js v1
|
|
105
|
+
|
|
106
|
+
const Berkeley: MinaNetwork = {
|
|
107
|
+
mina: [
|
|
108
|
+
"https://api.minascan.io/node/berkeley/v1/graphql",
|
|
109
|
+
"https://proxy.berkeley.minaexplorer.com/graphql",
|
|
110
|
+
],
|
|
111
|
+
archive: [
|
|
112
|
+
"https://api.minascan.io/archive/berkeley/v1/graphql",
|
|
113
|
+
"https://archive.berkeley.minaexplorer.com",
|
|
114
|
+
],
|
|
115
|
+
explorerAccountUrl: "https://minascan.io/berkeley/account/",
|
|
116
|
+
explorerTransactionUrl: "https://minascan.io/berkeley/tx/",
|
|
117
|
+
chainId: "berkeley",
|
|
118
|
+
name: "Berkeley",
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const TestWorld2: MinaNetwork = {
|
|
122
|
+
mina: ["https://api.minascan.io/node/testworld/v1/graphql"],
|
|
123
|
+
archive: ["https://archive.testworld.minaexplorer.com"],
|
|
124
|
+
explorerAccountUrl: "https://minascan.io/testworld/account/",
|
|
125
|
+
explorerTransactionUrl: "https://minascan.io/testworld/tx/",
|
|
126
|
+
chainId: "testworld2",
|
|
127
|
+
name: "TestWorld2",
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function createIpfsURL(params: {
|
|
2
|
+
hash: string;
|
|
3
|
+
gateway?: string;
|
|
4
|
+
apiToken?: string;
|
|
5
|
+
}): string {
|
|
6
|
+
let { hash, gateway, apiToken } = params;
|
|
7
|
+
gateway ??=
|
|
8
|
+
process.env.PINATA_IPFS_GATEWAY ??
|
|
9
|
+
process.env.NEXT_PUBLIC_PINATA_IPFS_GATEWAY ??
|
|
10
|
+
process.env.REACT_APP_PINATA_IPFS_GATEWAY;
|
|
11
|
+
apiToken ??=
|
|
12
|
+
process.env.PINATA_GATEWAY_TOKEN ??
|
|
13
|
+
process.env.NEXT_PUBLIC_PINATA_GATEWAY_TOKEN ??
|
|
14
|
+
process.env.REACT_APP_PINATA_GATEWAY_TOKEN;
|
|
15
|
+
|
|
16
|
+
if (!gateway) {
|
|
17
|
+
gateway = "https://gateway.pinata.cloud/ipfs/";
|
|
18
|
+
}
|
|
19
|
+
return gateway + hash + (apiToken ? "?pinataGatewayToken=" + apiToken : "");
|
|
20
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export async function pinJSON(params: {
|
|
2
|
+
data: string | object;
|
|
3
|
+
name?: string;
|
|
4
|
+
keyvalues?: object;
|
|
5
|
+
auth?: string;
|
|
6
|
+
}): Promise<string | undefined> {
|
|
7
|
+
const {
|
|
8
|
+
data,
|
|
9
|
+
name = "data.json",
|
|
10
|
+
keyvalues = { library: "zkcloudworker" },
|
|
11
|
+
} = params;
|
|
12
|
+
const auth =
|
|
13
|
+
params.auth ??
|
|
14
|
+
process.env.PINATA_JWT ??
|
|
15
|
+
process.env.NEXT_PUBLIC_PINATA_JWT ??
|
|
16
|
+
process.env.REACT_APP_PINATA_JWT;
|
|
17
|
+
if (!auth)
|
|
18
|
+
throw new Error(
|
|
19
|
+
"pinJSON: auth, PINATA_JWT, NEXT_PUBLIC_PINATA_JWT or REACT_APP_PINATA_JWT should be defined"
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const pinataData = {
|
|
24
|
+
pinataOptions: {
|
|
25
|
+
cidVersion: 1,
|
|
26
|
+
},
|
|
27
|
+
pinataMetadata: {
|
|
28
|
+
name,
|
|
29
|
+
keyvalues,
|
|
30
|
+
},
|
|
31
|
+
pinataContent: data,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const res = await fetch("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
Authorization: "Bearer " + auth,
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify(pinataData),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
throw new Error(`Pinata error: status: ${res.status} ${res.statusText}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const responseData = await res.json();
|
|
48
|
+
console.log("saveToIPFS result:", responseData);
|
|
49
|
+
return (
|
|
50
|
+
responseData as unknown as { IpfsHash: string | undefined } | undefined
|
|
51
|
+
)?.IpfsHash;
|
|
52
|
+
} catch (error: any) {
|
|
53
|
+
console.error("saveToIPFS error:", error?.message);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { fetchMinaAccount } from "../utils/fetch.js";
|
|
2
|
+
import { Mina, PublicKey, Field } from "o1js";
|
|
3
|
+
|
|
4
|
+
export async function accountExists(
|
|
5
|
+
address: string | PublicKey,
|
|
6
|
+
tokenId?: Field
|
|
7
|
+
): Promise<boolean> {
|
|
8
|
+
try {
|
|
9
|
+
const publicKey =
|
|
10
|
+
typeof address === "string" ? PublicKey.fromBase58(address) : address;
|
|
11
|
+
await fetchMinaAccount({ publicKey, tokenId, force: false });
|
|
12
|
+
return Mina.hasAccount(publicKey, tokenId);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function tokenBalance(
|
|
19
|
+
address: string | PublicKey,
|
|
20
|
+
tokenId?: Field
|
|
21
|
+
): Promise<number | undefined> {
|
|
22
|
+
try {
|
|
23
|
+
const publicKey =
|
|
24
|
+
typeof address === "string" ? PublicKey.fromBase58(address) : address;
|
|
25
|
+
await fetchMinaAccount({ publicKey, tokenId, force: false });
|
|
26
|
+
return Mina.hasAccount(publicKey, tokenId)
|
|
27
|
+
? Number(Mina.getAccount(publicKey, tokenId).balance.toBigInt())
|
|
28
|
+
: undefined;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error("Cannot fetch account balance", error);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function checkAddress(
|
|
36
|
+
address: string | undefined
|
|
37
|
+
): Promise<boolean> {
|
|
38
|
+
if (!address || typeof address !== "string") {
|
|
39
|
+
console.error("checkAddress params are invalid:", address);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const publicKey = PublicKey.fromBase58(address);
|
|
44
|
+
if (address !== publicKey.toBase58()) {
|
|
45
|
+
console.log(
|
|
46
|
+
"checkAddress: address is not valid",
|
|
47
|
+
address,
|
|
48
|
+
publicKey.toBase58()
|
|
49
|
+
);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error("checkAddress catch", { address, error });
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { BlockBerryChain } from "./chain.js";
|
|
2
|
+
|
|
3
|
+
export async function getZkAppTxsFromBlockBerry(params: {
|
|
4
|
+
account: string;
|
|
5
|
+
chain: BlockBerryChain;
|
|
6
|
+
blockBerryApiKey: string;
|
|
7
|
+
}): Promise<any> {
|
|
8
|
+
const { account, chain, blockBerryApiKey } = params;
|
|
9
|
+
const options = {
|
|
10
|
+
method: "GET",
|
|
11
|
+
headers: {
|
|
12
|
+
accept: "application/json",
|
|
13
|
+
"x-api-key": blockBerryApiKey,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
const controller = new AbortController();
|
|
18
|
+
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 seconds timeout
|
|
19
|
+
|
|
20
|
+
const response = await fetch(
|
|
21
|
+
`https://api.blockberry.one/mina-${chain}/v1/zkapps/accounts/${account}/txs?size=10&orderBy=DESC&sortBy=AGE`,
|
|
22
|
+
{
|
|
23
|
+
...options,
|
|
24
|
+
signal: controller.signal,
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
clearTimeout(timeoutId); // Clear the timeout if the fetch completes successfully
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
console.error(
|
|
31
|
+
"Cannot fetch zkApp txs for account:",
|
|
32
|
+
account,
|
|
33
|
+
chain,
|
|
34
|
+
response.statusText
|
|
35
|
+
);
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const result = await response.json();
|
|
39
|
+
//console.log("zkAppTxs", result);
|
|
40
|
+
return result;
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error(
|
|
43
|
+
"Cannot fetch zkApp txs for account - catch:",
|
|
44
|
+
account,
|
|
45
|
+
chain,
|
|
46
|
+
err
|
|
47
|
+
);
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function getPaymentTxsFromBlockBerry(params: {
|
|
53
|
+
account: string;
|
|
54
|
+
chain: BlockBerryChain;
|
|
55
|
+
blockBerryApiKey: string;
|
|
56
|
+
}): Promise<any> {
|
|
57
|
+
const { account, chain, blockBerryApiKey } = params;
|
|
58
|
+
const options = {
|
|
59
|
+
method: "GET",
|
|
60
|
+
headers: {
|
|
61
|
+
accept: "application/json",
|
|
62
|
+
"x-api-key": blockBerryApiKey,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 seconds timeout
|
|
69
|
+
|
|
70
|
+
const response = await fetch(
|
|
71
|
+
`https://api.blockberry.one/mina-${chain}/v1/accounts/` +
|
|
72
|
+
account +
|
|
73
|
+
"/txs?page=0&size=1&orderBy=DESC&sortBy=AGE&direction=OUT",
|
|
74
|
+
{
|
|
75
|
+
...options,
|
|
76
|
+
signal: controller.signal,
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
clearTimeout(timeoutId); // Clear the timeout if the fetch completes successfully
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
console.error(
|
|
83
|
+
"Cannot fetch payment txs for account:",
|
|
84
|
+
account,
|
|
85
|
+
chain,
|
|
86
|
+
response.statusText
|
|
87
|
+
);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const result = await response.json();
|
|
91
|
+
//console.log("paymentTxs", result);
|
|
92
|
+
return result;
|
|
93
|
+
} catch (err) {
|
|
94
|
+
console.error(
|
|
95
|
+
"Cannot fetch payment txs for account - catch:",
|
|
96
|
+
account,
|
|
97
|
+
chain,
|
|
98
|
+
err
|
|
99
|
+
);
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function getZkAppTxFromBlockBerry(params: {
|
|
105
|
+
hash: string;
|
|
106
|
+
chain: BlockBerryChain;
|
|
107
|
+
blockBerryApiKey: string;
|
|
108
|
+
}): Promise<any> {
|
|
109
|
+
const { hash, chain, blockBerryApiKey } = params;
|
|
110
|
+
const options = {
|
|
111
|
+
method: "GET",
|
|
112
|
+
headers: {
|
|
113
|
+
accept: "application/json",
|
|
114
|
+
"x-api-key": blockBerryApiKey,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
try {
|
|
118
|
+
const controller = new AbortController();
|
|
119
|
+
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 seconds timeout
|
|
120
|
+
|
|
121
|
+
const response = await fetch(
|
|
122
|
+
`https://api.blockberry.one/mina-${chain}/v1/zkapps/txs/${hash}`,
|
|
123
|
+
{
|
|
124
|
+
...options,
|
|
125
|
+
signal: controller.signal,
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
clearTimeout(timeoutId); // Clear the timeout if the fetch completes successfully
|
|
130
|
+
if (response.ok) {
|
|
131
|
+
const result = await response.json();
|
|
132
|
+
return result;
|
|
133
|
+
} else {
|
|
134
|
+
console.error(
|
|
135
|
+
"getZkAppTxFromBlockBerry error while getting hash - not ok",
|
|
136
|
+
{ hash, chain, text: response.statusText, status: response.status }
|
|
137
|
+
);
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.error(
|
|
142
|
+
"getZkAppTxFromBlockBerry error while getting mainnet hash - catch",
|
|
143
|
+
hash,
|
|
144
|
+
chain,
|
|
145
|
+
err
|
|
146
|
+
);
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function getZkAppFromBlockBerry(params: {
|
|
152
|
+
account: string;
|
|
153
|
+
chain: BlockBerryChain;
|
|
154
|
+
blockBerryApiKey: string;
|
|
155
|
+
}): Promise<any> {
|
|
156
|
+
const { account, chain, blockBerryApiKey } = params;
|
|
157
|
+
const options = {
|
|
158
|
+
method: "GET",
|
|
159
|
+
headers: {
|
|
160
|
+
accept: "application/json",
|
|
161
|
+
"x-api-key": blockBerryApiKey,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
try {
|
|
165
|
+
const controller = new AbortController();
|
|
166
|
+
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 seconds timeout
|
|
167
|
+
|
|
168
|
+
const response = await fetch(
|
|
169
|
+
`https://api.blockberry.one/mina-${chain}/v1/zkapps/${account}`,
|
|
170
|
+
{
|
|
171
|
+
...options,
|
|
172
|
+
signal: controller.signal,
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
clearTimeout(timeoutId); // Clear the timeout if the fetch completes successfully
|
|
177
|
+
if (response.ok) {
|
|
178
|
+
const result = await response.json();
|
|
179
|
+
return result;
|
|
180
|
+
} else {
|
|
181
|
+
console.error("getZkAppFromBlockBerry error while getting account", {
|
|
182
|
+
account,
|
|
183
|
+
chain,
|
|
184
|
+
text: response.statusText,
|
|
185
|
+
status: response.status,
|
|
186
|
+
});
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
} catch (err) {
|
|
190
|
+
console.error(
|
|
191
|
+
"getZkAppFromBlockBerry error while getting account - catch",
|
|
192
|
+
account,
|
|
193
|
+
chain,
|
|
194
|
+
err
|
|
195
|
+
);
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type BlockBerryChain = "mainnet" | "devnet";
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { BlockBerryChain } from "./chain.js";
|
|
2
|
+
import {
|
|
3
|
+
getZkAppTxsFromBlockBerry,
|
|
4
|
+
getPaymentTxsFromBlockBerry,
|
|
5
|
+
} from "./blockberry.js";
|
|
6
|
+
import { fetchMinaAccount } from "../utils/fetch.js";
|
|
7
|
+
import { getCurrentNetwork } from "../utils/mina.js";
|
|
8
|
+
import { Mina, PublicKey } from "o1js";
|
|
9
|
+
import { blockchain } from "../networks.js";
|
|
10
|
+
|
|
11
|
+
export async function getNonce(params: {
|
|
12
|
+
account: string;
|
|
13
|
+
chain: BlockBerryChain;
|
|
14
|
+
blockBerryApiKey: string;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
nonce: number;
|
|
18
|
+
message?: string;
|
|
19
|
+
}> {
|
|
20
|
+
const { account, chain, blockBerryApiKey } = params;
|
|
21
|
+
try {
|
|
22
|
+
if (account === undefined || account === null || account === "") {
|
|
23
|
+
return {
|
|
24
|
+
success: false,
|
|
25
|
+
nonce: -1,
|
|
26
|
+
message: "Account is required",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
blockBerryApiKey === undefined ||
|
|
32
|
+
blockBerryApiKey === null ||
|
|
33
|
+
blockBerryApiKey === ""
|
|
34
|
+
) {
|
|
35
|
+
return {
|
|
36
|
+
success: false,
|
|
37
|
+
nonce: -1,
|
|
38
|
+
message: "blockBerryApiKey is required",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const zkAppTxsPromise = getZkAppTxsFromBlockBerry({
|
|
42
|
+
account,
|
|
43
|
+
chain,
|
|
44
|
+
blockBerryApiKey,
|
|
45
|
+
});
|
|
46
|
+
const paymentTxs = getPaymentTxsFromBlockBerry({
|
|
47
|
+
account,
|
|
48
|
+
chain,
|
|
49
|
+
blockBerryApiKey,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const paymentNonce = (await paymentTxs)?.data[0]?.nonce ?? -1;
|
|
53
|
+
let zkNonce = -1;
|
|
54
|
+
let found = false;
|
|
55
|
+
const zkAppTxs = await zkAppTxsPromise;
|
|
56
|
+
const size = zkAppTxs?.data?.length ?? 0;
|
|
57
|
+
let i = 0;
|
|
58
|
+
while (!found && i < size) {
|
|
59
|
+
if (zkAppTxs?.data[i]?.proverAddress === account) {
|
|
60
|
+
zkNonce = zkAppTxs?.data[i]?.nonce;
|
|
61
|
+
found = true;
|
|
62
|
+
}
|
|
63
|
+
i++;
|
|
64
|
+
}
|
|
65
|
+
const nonce = Math.max(zkNonce, paymentNonce);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
success: true,
|
|
69
|
+
nonce,
|
|
70
|
+
};
|
|
71
|
+
} catch (error) {
|
|
72
|
+
return {
|
|
73
|
+
success: false,
|
|
74
|
+
nonce: -1,
|
|
75
|
+
message: String(error),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function getAccountNonce(params: {
|
|
81
|
+
account: string;
|
|
82
|
+
chain?: blockchain;
|
|
83
|
+
blockBerryApiKey?: string;
|
|
84
|
+
verbose?: boolean;
|
|
85
|
+
}): Promise<number> {
|
|
86
|
+
const {
|
|
87
|
+
account,
|
|
88
|
+
chain = getCurrentNetwork().network.chainId,
|
|
89
|
+
blockBerryApiKey,
|
|
90
|
+
verbose = true,
|
|
91
|
+
} = params;
|
|
92
|
+
const canUseBlockBerry =
|
|
93
|
+
blockBerryApiKey !== undefined &&
|
|
94
|
+
(chain === "devnet" || chain === "mainnet");
|
|
95
|
+
if (chain === "zeko") {
|
|
96
|
+
const publicKey = PublicKey.fromBase58(account);
|
|
97
|
+
await fetchMinaAccount({ publicKey });
|
|
98
|
+
const nonce = Number(Mina.getAccount(publicKey).nonce.toBigint());
|
|
99
|
+
return nonce;
|
|
100
|
+
} else {
|
|
101
|
+
const blockberryNoncePromise = canUseBlockBerry
|
|
102
|
+
? getNonce({
|
|
103
|
+
account,
|
|
104
|
+
blockBerryApiKey,
|
|
105
|
+
chain,
|
|
106
|
+
})
|
|
107
|
+
: undefined;
|
|
108
|
+
const publicKey = PublicKey.fromBase58(account);
|
|
109
|
+
await fetchMinaAccount({ publicKey });
|
|
110
|
+
const senderNonce = Number(Mina.getAccount(publicKey).nonce.toBigint());
|
|
111
|
+
const blockberryNonce = blockberryNoncePromise
|
|
112
|
+
? (await blockberryNoncePromise).nonce ?? -1
|
|
113
|
+
: -1;
|
|
114
|
+
const nonce = Math.max(senderNonce, blockberryNonce + 1);
|
|
115
|
+
if (verbose && nonce > senderNonce)
|
|
116
|
+
console.log(
|
|
117
|
+
`Nonce changed from ${senderNonce} to ${nonce} for ${account}`
|
|
118
|
+
);
|
|
119
|
+
return nonce;
|
|
120
|
+
}
|
|
121
|
+
}
|