@silvana-one/coordination 1.0.37 → 1.0.38
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/index.cjs +54 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/keypair.d.ts +29 -0
- package/dist/node/keypair.js +77 -0
- package/dist/node/keypair.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/keypair.d.ts +29 -0
- package/dist/web/keypair.js +77 -0
- package/dist/web/keypair.js.map +1 -0
- package/package.json +3 -2
- package/src/index.ts +1 -0
- package/src/keypair.ts +106 -0
package/dist/node/index.cjs
CHANGED
|
@@ -47,6 +47,7 @@ __export(index_exports, {
|
|
|
47
47
|
fetchSuiDynamicField: () => fetchSuiDynamicField,
|
|
48
48
|
fetchSuiDynamicFieldsList: () => fetchSuiDynamicFieldsList,
|
|
49
49
|
fetchSuiObject: () => fetchSuiObject,
|
|
50
|
+
generateEd25519: () => generateEd25519,
|
|
50
51
|
getIPFSUrl: () => getIPFSUrl,
|
|
51
52
|
getState: () => getState,
|
|
52
53
|
getSuiAddress: () => getSuiAddress,
|
|
@@ -61,6 +62,7 @@ __export(index_exports, {
|
|
|
61
62
|
saveToIPFS: () => saveToIPFS,
|
|
62
63
|
saveToWalrus: () => saveToWalrus,
|
|
63
64
|
signFields: () => signFields,
|
|
65
|
+
signMessage: () => signMessage,
|
|
64
66
|
silvanaFaucet: () => silvanaFaucet,
|
|
65
67
|
silvanaFaucetGetKey: () => silvanaFaucetGetKey,
|
|
66
68
|
silvanaFaucetPingKey: () => silvanaFaucetPingKey,
|
|
@@ -73,6 +75,7 @@ __export(index_exports, {
|
|
|
73
75
|
u256ToFields: () => u256ToFields,
|
|
74
76
|
u256ToPublicKey: () => u256ToPublicKey,
|
|
75
77
|
verifyFields: () => verifyFields,
|
|
78
|
+
verifyWithAddress: () => verifyWithAddress,
|
|
76
79
|
waitTx: () => waitTx,
|
|
77
80
|
walrusDaemon: () => walrusDaemon
|
|
78
81
|
});
|
|
@@ -2114,6 +2117,54 @@ async function getState(params = {}) {
|
|
|
2114
2117
|
}
|
|
2115
2118
|
return state;
|
|
2116
2119
|
}
|
|
2120
|
+
|
|
2121
|
+
// dist/node/keypair.js
|
|
2122
|
+
var import_ed255194 = require("@mysten/sui/keypairs/ed25519");
|
|
2123
|
+
var import_ed255195 = require("@mysten/sui/keypairs/ed25519");
|
|
2124
|
+
var import_utils5 = require("@mysten/sui/utils");
|
|
2125
|
+
function generateEd25519() {
|
|
2126
|
+
const keypair = new import_ed255194.Ed25519Keypair();
|
|
2127
|
+
const suiPrivateKey = keypair.getSecretKey();
|
|
2128
|
+
const address = keypair.getPublicKey().toSuiAddress();
|
|
2129
|
+
return {
|
|
2130
|
+
address,
|
|
2131
|
+
suiPrivateKey,
|
|
2132
|
+
keypair
|
|
2133
|
+
};
|
|
2134
|
+
}
|
|
2135
|
+
async function signMessage(params) {
|
|
2136
|
+
const { secretKey, message } = params;
|
|
2137
|
+
const keypair = import_ed255194.Ed25519Keypair.fromSecretKey(secretKey);
|
|
2138
|
+
const messageBytes = message instanceof Uint8Array ? message : new Uint8Array(message);
|
|
2139
|
+
const signature = await keypair.sign(messageBytes);
|
|
2140
|
+
const publicKeyBytes = keypair.getPublicKey().toRawBytes();
|
|
2141
|
+
const fullSignature = new Uint8Array(1 + signature.length + publicKeyBytes.length);
|
|
2142
|
+
fullSignature[0] = 0;
|
|
2143
|
+
fullSignature.set(signature, 1);
|
|
2144
|
+
fullSignature.set(publicKeyBytes, 1 + signature.length);
|
|
2145
|
+
return (0, import_utils5.toBase64)(fullSignature);
|
|
2146
|
+
}
|
|
2147
|
+
async function verifyWithAddress(address, message, signature) {
|
|
2148
|
+
const messageBytes = message instanceof Uint8Array ? message : new Uint8Array(message);
|
|
2149
|
+
try {
|
|
2150
|
+
const sigBytes = (0, import_utils5.fromBase64)(signature);
|
|
2151
|
+
if (sigBytes.length !== 97) {
|
|
2152
|
+
return false;
|
|
2153
|
+
}
|
|
2154
|
+
if (sigBytes[0] !== 0) {
|
|
2155
|
+
return false;
|
|
2156
|
+
}
|
|
2157
|
+
const publicKeyBytes = sigBytes.slice(65, 97);
|
|
2158
|
+
const publicKey = new import_ed255195.Ed25519PublicKey(publicKeyBytes);
|
|
2159
|
+
const derivedAddress = publicKey.toSuiAddress();
|
|
2160
|
+
if (derivedAddress !== address) {
|
|
2161
|
+
return false;
|
|
2162
|
+
}
|
|
2163
|
+
return await publicKey.verify(messageBytes, signature);
|
|
2164
|
+
} catch {
|
|
2165
|
+
return false;
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2117
2168
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2118
2169
|
0 && (module.exports = {
|
|
2119
2170
|
AgentRegistry,
|
|
@@ -2133,6 +2184,7 @@ async function getState(params = {}) {
|
|
|
2133
2184
|
fetchSuiDynamicField,
|
|
2134
2185
|
fetchSuiDynamicFieldsList,
|
|
2135
2186
|
fetchSuiObject,
|
|
2187
|
+
generateEd25519,
|
|
2136
2188
|
getIPFSUrl,
|
|
2137
2189
|
getState,
|
|
2138
2190
|
getSuiAddress,
|
|
@@ -2147,6 +2199,7 @@ async function getState(params = {}) {
|
|
|
2147
2199
|
saveToIPFS,
|
|
2148
2200
|
saveToWalrus,
|
|
2149
2201
|
signFields,
|
|
2202
|
+
signMessage,
|
|
2150
2203
|
silvanaFaucet,
|
|
2151
2204
|
silvanaFaucetGetKey,
|
|
2152
2205
|
silvanaFaucetPingKey,
|
|
@@ -2159,6 +2212,7 @@ async function getState(params = {}) {
|
|
|
2159
2212
|
u256ToFields,
|
|
2160
2213
|
u256ToPublicKey,
|
|
2161
2214
|
verifyFields,
|
|
2215
|
+
verifyWithAddress,
|
|
2162
2216
|
waitTx,
|
|
2163
2217
|
walrusDaemon
|
|
2164
2218
|
});
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.js
CHANGED
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
2
|
+
export interface GeneratedKeypair {
|
|
3
|
+
address: string;
|
|
4
|
+
suiPrivateKey: string;
|
|
5
|
+
keypair: Ed25519Keypair;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Generates a new Ed25519 keypair
|
|
9
|
+
* @returns Generated keypair with address, and sui private key
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateEd25519(): GeneratedKeypair;
|
|
12
|
+
/**
|
|
13
|
+
* Signs a message with the given secret key
|
|
14
|
+
* @param secretKey - 32-byte secret key as base64 or bech32 string
|
|
15
|
+
* @param message - Message to sign as number[] or Uint8Array
|
|
16
|
+
* @returns Base64-encoded serialized signature string
|
|
17
|
+
*/
|
|
18
|
+
export declare function signMessage(params: {
|
|
19
|
+
secretKey: string;
|
|
20
|
+
message: number[] | Uint8Array;
|
|
21
|
+
}): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Verifies a signature against an address
|
|
24
|
+
* @param address - Sui address
|
|
25
|
+
* @param message - Original message as number[] or Uint8Array
|
|
26
|
+
* @param signature - Base64-encoded serialized signature string
|
|
27
|
+
* @returns true if signature is valid, false otherwise
|
|
28
|
+
*/
|
|
29
|
+
export declare function verifyWithAddress(address: string, message: number[] | Uint8Array, signature: string): Promise<boolean>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
2
|
+
import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
|
|
3
|
+
import { fromBase64, toBase64 } from "@mysten/sui/utils";
|
|
4
|
+
/**
|
|
5
|
+
* Generates a new Ed25519 keypair
|
|
6
|
+
* @returns Generated keypair with address, and sui private key
|
|
7
|
+
*/
|
|
8
|
+
export function generateEd25519() {
|
|
9
|
+
const keypair = new Ed25519Keypair();
|
|
10
|
+
const suiPrivateKey = keypair.getSecretKey();
|
|
11
|
+
const address = keypair.getPublicKey().toSuiAddress();
|
|
12
|
+
return {
|
|
13
|
+
address,
|
|
14
|
+
suiPrivateKey,
|
|
15
|
+
keypair,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Signs a message with the given secret key
|
|
20
|
+
* @param secretKey - 32-byte secret key as base64 or bech32 string
|
|
21
|
+
* @param message - Message to sign as number[] or Uint8Array
|
|
22
|
+
* @returns Base64-encoded serialized signature string
|
|
23
|
+
*/
|
|
24
|
+
export async function signMessage(params) {
|
|
25
|
+
const { secretKey, message } = params;
|
|
26
|
+
const keypair = Ed25519Keypair.fromSecretKey(secretKey);
|
|
27
|
+
// Convert message to Uint8Array if needed
|
|
28
|
+
const messageBytes = message instanceof Uint8Array ? message : new Uint8Array(message);
|
|
29
|
+
// Sign the message - this returns just the 64-byte signature
|
|
30
|
+
const signature = await keypair.sign(messageBytes);
|
|
31
|
+
// Get the public key bytes
|
|
32
|
+
const publicKeyBytes = keypair.getPublicKey().toRawBytes();
|
|
33
|
+
// Construct the full Sui signature format: flag || signature || publicKey
|
|
34
|
+
const fullSignature = new Uint8Array(1 + signature.length + publicKeyBytes.length);
|
|
35
|
+
fullSignature[0] = 0x00; // Ed25519 flag
|
|
36
|
+
fullSignature.set(signature, 1);
|
|
37
|
+
fullSignature.set(publicKeyBytes, 1 + signature.length);
|
|
38
|
+
// Return as base64 string (what the SDK expects)
|
|
39
|
+
return toBase64(fullSignature);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Verifies a signature against an address
|
|
43
|
+
* @param address - Sui address
|
|
44
|
+
* @param message - Original message as number[] or Uint8Array
|
|
45
|
+
* @param signature - Base64-encoded serialized signature string
|
|
46
|
+
* @returns true if signature is valid, false otherwise
|
|
47
|
+
*/
|
|
48
|
+
export async function verifyWithAddress(address, message, signature) {
|
|
49
|
+
// Convert message to Uint8Array if needed
|
|
50
|
+
const messageBytes = message instanceof Uint8Array ? message : new Uint8Array(message);
|
|
51
|
+
try {
|
|
52
|
+
// Decode the base64 signature
|
|
53
|
+
const sigBytes = fromBase64(signature);
|
|
54
|
+
if (sigBytes.length !== 97) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// Check the flag byte (0x00 for Ed25519)
|
|
58
|
+
if (sigBytes[0] !== 0x00) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
// Extract the public key (last 32 bytes)
|
|
62
|
+
const publicKeyBytes = sigBytes.slice(65, 97);
|
|
63
|
+
// Create an Ed25519PublicKey from the raw bytes
|
|
64
|
+
const publicKey = new Ed25519PublicKey(publicKeyBytes);
|
|
65
|
+
// Verify the derived address matches
|
|
66
|
+
const derivedAddress = publicKey.toSuiAddress();
|
|
67
|
+
if (derivedAddress !== address) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
// Verify the signature using the SDK's expected format (base64 string)
|
|
71
|
+
return await publicKey.verify(messageBytes, signature);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=keypair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keypair.js","sourceRoot":"","sources":["../../src/keypair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAQzD;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,OAAO,GAAG,IAAI,cAAc,EAAE,CAAC;IACrC,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAC7C,M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