@silvana-one/coordination 1.0.23 → 1.0.25
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/dist/node/build.d.ts +5 -0
- package/dist/node/build.js +21 -0
- package/dist/node/build.js.map +1 -0
- package/dist/node/faucet.d.ts +34 -0
- package/dist/node/faucet.js +91 -0
- package/dist/node/faucet.js.map +1 -0
- package/dist/node/index.cjs +337 -4
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.js +5 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/ipfs.d.ts +13 -0
- package/dist/node/ipfs.js +88 -0
- package/dist/node/ipfs.js.map +1 -0
- package/dist/node/public-key.d.ts +24 -0
- package/dist/node/public-key.js +44 -0
- package/dist/node/public-key.js.map +1 -0
- package/dist/node/publish.js.map +1 -1
- package/dist/node/upgrade.js +1 -12
- package/dist/node/upgrade.js.map +1 -1
- package/dist/node/walrus.d.ts +12 -0
- package/dist/node/walrus.js +73 -0
- package/dist/node/walrus.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/build.d.ts +5 -0
- package/dist/web/build.js +21 -0
- package/dist/web/build.js.map +1 -0
- package/dist/web/faucet.d.ts +34 -0
- package/dist/web/faucet.js +91 -0
- package/dist/web/faucet.js.map +1 -0
- package/dist/web/index.d.ts +5 -0
- package/dist/web/index.js +5 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/ipfs.d.ts +13 -0
- package/dist/web/ipfs.js +88 -0
- package/dist/web/ipfs.js.map +1 -0
- package/dist/web/public-key.d.ts +24 -0
- package/dist/web/public-key.js +44 -0
- package/dist/web/public-key.js.map +1 -0
- package/dist/web/publish.js.map +1 -1
- package/dist/web/upgrade.js +1 -12
- package/dist/web/upgrade.js.map +1 -1
- package/dist/web/walrus.d.ts +12 -0
- package/dist/web/walrus.js +73 -0
- package/dist/web/walrus.js.map +1 -0
- package/package.json +6 -5
- package/src/build.ts +33 -0
- package/src/faucet.ts +145 -0
- package/src/index.ts +5 -0
- package/src/ipfs.ts +105 -0
- package/src/public-key.ts +66 -0
- package/src/publish.ts +0 -2
- package/src/upgrade.ts +1 -18
- package/src/walrus.ts +96 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Client from "mina-signer";
|
|
2
|
+
import { convertFieldsToPublicKey } from "./base58/public-key.js";
|
|
3
|
+
|
|
4
|
+
const client = new Client({
|
|
5
|
+
network: "testnet",
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export function publicKeyToU256(publicKey: string): bigint {
|
|
9
|
+
const raw = client.publicKeyToRaw(publicKey);
|
|
10
|
+
const swappedRaw =
|
|
11
|
+
raw
|
|
12
|
+
.match(/.{1,2}/g)
|
|
13
|
+
?.reverse()
|
|
14
|
+
.join("") || "";
|
|
15
|
+
const u256 = BigInt("0x" + swappedRaw);
|
|
16
|
+
return u256;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const MAX_BIT: bigint = 2n ** 255n;
|
|
20
|
+
|
|
21
|
+
export function u256ToFields(u256: bigint): {
|
|
22
|
+
x: bigint;
|
|
23
|
+
isOdd: boolean;
|
|
24
|
+
} {
|
|
25
|
+
const isOdd = (u256 & MAX_BIT) != 0n;
|
|
26
|
+
const x = u256 - (isOdd ? MAX_BIT : 0n);
|
|
27
|
+
return { x, isOdd };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function u256ToPublicKey(u256: bigint): string {
|
|
31
|
+
const { x, isOdd } = u256ToFields(u256);
|
|
32
|
+
return convertFieldsToPublicKey({ x, isOdd });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function convertMinaPublicKey(publicKey: string): {
|
|
36
|
+
x: bigint;
|
|
37
|
+
isOdd: boolean;
|
|
38
|
+
} {
|
|
39
|
+
const u256 = publicKeyToU256(publicKey);
|
|
40
|
+
return u256ToFields(u256);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function convertMinaPublicKeyToFields(publicKey?: string): bigint[] {
|
|
44
|
+
if (!publicKey) return [];
|
|
45
|
+
const { x, isOdd } = convertMinaPublicKey(publicKey);
|
|
46
|
+
return [x, isOdd ? 1n : 0n];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function signFields(params: { privateKey: string; fields: bigint[] }): {
|
|
50
|
+
signature: string;
|
|
51
|
+
data: bigint[];
|
|
52
|
+
publicKey: string;
|
|
53
|
+
} {
|
|
54
|
+
const { privateKey, fields } = params;
|
|
55
|
+
const signedData = client.signFields(fields.map(BigInt), privateKey);
|
|
56
|
+
return signedData;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function verifyFields(params: {
|
|
60
|
+
publicKey: string;
|
|
61
|
+
fields: bigint[];
|
|
62
|
+
signature: string;
|
|
63
|
+
}): boolean {
|
|
64
|
+
const { publicKey, fields, signature } = params;
|
|
65
|
+
return client.verifyFields({ data: fields, publicKey, signature });
|
|
66
|
+
}
|
package/src/publish.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Secp256k1Keypair } from "@mysten/sui/keypairs/secp256k1";
|
|
2
2
|
import { Transaction } from "@mysten/sui/transactions";
|
|
3
|
-
import { SignatureWithBytes } from "@mysten/sui/cryptography";
|
|
4
|
-
import { suiClient } from "./sui-client.js";
|
|
5
3
|
|
|
6
4
|
export async function buildPublishTx(params: {
|
|
7
5
|
modules: string[];
|
package/src/upgrade.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { Secp256k1Keypair } from "@mysten/sui/keypairs/secp256k1";
|
|
2
|
-
import {
|
|
3
|
-
Transaction,
|
|
4
|
-
TransactionResult,
|
|
5
|
-
UpgradePolicy,
|
|
6
|
-
} from "@mysten/sui/transactions";
|
|
7
|
-
import { UpgradeInfo } from "@mysten/sui/client";
|
|
8
|
-
import { SignatureWithBytes } from "@mysten/sui/cryptography";
|
|
2
|
+
import { Transaction, UpgradePolicy } from "@mysten/sui/transactions";
|
|
9
3
|
import { suiClient } from "./sui-client.js";
|
|
10
4
|
|
|
11
5
|
export async function buildUpgradeTx(params: {
|
|
@@ -43,12 +37,10 @@ export async function buildUpgradeTx(params: {
|
|
|
43
37
|
modules,
|
|
44
38
|
dependencies,
|
|
45
39
|
});
|
|
46
|
-
//console.log("upgradeData", upgradeData);
|
|
47
40
|
const commitData = tx.moveCall({
|
|
48
41
|
target: "0x2::package::commit_upgrade",
|
|
49
42
|
arguments: [tx.object(upgradeCap), upgradeData],
|
|
50
43
|
});
|
|
51
|
-
//console.log("commitData", commitData);
|
|
52
44
|
const paginatedCoins = await suiClient.getCoins({
|
|
53
45
|
owner: address,
|
|
54
46
|
});
|
|
@@ -59,20 +51,11 @@ export async function buildUpgradeTx(params: {
|
|
|
59
51
|
digest: coin.digest,
|
|
60
52
|
};
|
|
61
53
|
});
|
|
62
|
-
//console.log("coins", coins);
|
|
63
54
|
|
|
64
55
|
tx.setSender(address);
|
|
65
56
|
tx.setGasOwner(address);
|
|
66
57
|
tx.setGasPayment(coins);
|
|
67
|
-
//console.log("tx", await tx.toJSON());
|
|
68
58
|
tx.setGasBudget(300_000_000);
|
|
69
59
|
|
|
70
|
-
//console.log("tx", await tx.toJSON());
|
|
71
|
-
console.time("sign");
|
|
72
|
-
// const signedTx = await tx.sign({
|
|
73
|
-
// signer: keypair,
|
|
74
|
-
// client: suiClient,
|
|
75
|
-
// });
|
|
76
|
-
console.timeEnd("sign");
|
|
77
60
|
return { tx };
|
|
78
61
|
}
|
package/src/walrus.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export const walrusDaemon = (process.env.NEXT_PUBLIC_WALRUS_DAEMON ||
|
|
2
|
+
process.env.WALRUS_DAEMON ||
|
|
3
|
+
"testnet") as "local" | "testnet";
|
|
4
|
+
const daemon: "local" | "testnet" =
|
|
5
|
+
walrusDaemon === "local" ? "local" : "testnet";
|
|
6
|
+
const basePublisherUrl =
|
|
7
|
+
daemon === "local"
|
|
8
|
+
? "http://127.0.0.1:31415"
|
|
9
|
+
: "https://wal-publisher-testnet.staketab.org";
|
|
10
|
+
//"https://publisher.walrus-testnet.walrus.space";
|
|
11
|
+
const readerUrl =
|
|
12
|
+
daemon === "local"
|
|
13
|
+
? "http://127.0.0.1:31415/v1/blobs/"
|
|
14
|
+
: "https://wal-aggregator-testnet.staketab.org/v1/blobs/";
|
|
15
|
+
//"https://aggregator.walrus-testnet.walrus.space/v1/blobs/";
|
|
16
|
+
|
|
17
|
+
const MIN_EPOCHS = 14;
|
|
18
|
+
const MAX_EPOCHS = 53;
|
|
19
|
+
|
|
20
|
+
export async function saveToWalrus({
|
|
21
|
+
data,
|
|
22
|
+
address,
|
|
23
|
+
numEpochs = MIN_EPOCHS,
|
|
24
|
+
}: {
|
|
25
|
+
data: string;
|
|
26
|
+
address?: string;
|
|
27
|
+
numEpochs?: number;
|
|
28
|
+
}): Promise<string | undefined> {
|
|
29
|
+
let sendToParam = address ? `&send_object_to=${address}` : "";
|
|
30
|
+
let epochs =
|
|
31
|
+
numEpochs < MIN_EPOCHS
|
|
32
|
+
? MIN_EPOCHS
|
|
33
|
+
: numEpochs > MAX_EPOCHS
|
|
34
|
+
? MAX_EPOCHS
|
|
35
|
+
: numEpochs;
|
|
36
|
+
console.log("Writing to Walrus");
|
|
37
|
+
console.time("written");
|
|
38
|
+
const response = await fetch(
|
|
39
|
+
`${basePublisherUrl}/v1/blobs?epochs=${epochs}${sendToParam}`,
|
|
40
|
+
{
|
|
41
|
+
method: "PUT",
|
|
42
|
+
body: data,
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
console.timeEnd("written");
|
|
46
|
+
if (response.status === 200) {
|
|
47
|
+
const info = await response.json();
|
|
48
|
+
//console.log("info", info);
|
|
49
|
+
const blobId =
|
|
50
|
+
info?.newlyCreated?.blobObject?.blobId ?? info?.alreadyCertified?.blobId;
|
|
51
|
+
console.log("Walrus blobId", blobId);
|
|
52
|
+
return blobId;
|
|
53
|
+
} else {
|
|
54
|
+
console.error("saveToDA failed:", {
|
|
55
|
+
statusText: response.statusText,
|
|
56
|
+
status: response.status,
|
|
57
|
+
});
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function readFromWalrus({
|
|
63
|
+
blobId,
|
|
64
|
+
}: {
|
|
65
|
+
blobId: string;
|
|
66
|
+
}): Promise<string | undefined> {
|
|
67
|
+
if (!blobId) {
|
|
68
|
+
throw new Error("blobId is not provided");
|
|
69
|
+
}
|
|
70
|
+
console.log("Reading walrus blob", blobId);
|
|
71
|
+
console.time("read");
|
|
72
|
+
const response = await fetch(`${readerUrl}${blobId}`);
|
|
73
|
+
console.timeEnd("read");
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
console.error("readFromDA failed:", {
|
|
76
|
+
statusText: response.statusText,
|
|
77
|
+
status: response.status,
|
|
78
|
+
});
|
|
79
|
+
return undefined;
|
|
80
|
+
} else {
|
|
81
|
+
const blob = await response.text();
|
|
82
|
+
//console.log("blob", blob);
|
|
83
|
+
return blob;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function getWalrusUrl(params: {
|
|
88
|
+
blobId: string;
|
|
89
|
+
}): Promise<string> {
|
|
90
|
+
const { blobId } = params;
|
|
91
|
+
if (!blobId) {
|
|
92
|
+
throw new Error("blobId is not set");
|
|
93
|
+
}
|
|
94
|
+
const url = `${readerUrl}${blobId}`;
|
|
95
|
+
return url;
|
|
96
|
+
}
|