anymal-protocol 1.0.114 → 1.0.115
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/chunk-43I5M7QS.mjs +93 -0
- package/dist/chunk-5UXBNDDZ.mjs +93 -0
- package/dist/chunk-DIGESQEI.mjs +91 -0
- package/dist/chunk-KEC6WLEL.mjs +93 -0
- package/dist/chunk-QHK3YPLJ.mjs +93 -0
- package/dist/index.js +48 -4
- package/dist/index.mjs +49 -5
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/helpers/CryptoUtils.tsx
|
|
9
|
+
import { ec as EC } from "elliptic";
|
|
10
|
+
var ec = new EC("secp256k1");
|
|
11
|
+
var Network = /* @__PURE__ */ ((Network2) => {
|
|
12
|
+
Network2["Testnet"] = "testnet";
|
|
13
|
+
Network2["Localnet"] = "localnet";
|
|
14
|
+
return Network2;
|
|
15
|
+
})(Network || {});
|
|
16
|
+
var NETWORK_HOSTS = {
|
|
17
|
+
["testnet" /* Testnet */]: "https://dev-db.petastic.com",
|
|
18
|
+
["localnet" /* Localnet */]: "http://host.docker.internal:9181"
|
|
19
|
+
};
|
|
20
|
+
function loadExistingSecp256k1PrivateKey(hexKey) {
|
|
21
|
+
if (!hexKey) {
|
|
22
|
+
throw new Error("Private key hex must be provided");
|
|
23
|
+
}
|
|
24
|
+
return ec.keyFromPrivate(hexKey, "hex");
|
|
25
|
+
}
|
|
26
|
+
function serializePublicKeyCompressed(keyPair) {
|
|
27
|
+
return keyPair.getPublic(true, "hex");
|
|
28
|
+
}
|
|
29
|
+
function base64url(input) {
|
|
30
|
+
let buf;
|
|
31
|
+
if (typeof input === "string") buf = Buffer.from(input);
|
|
32
|
+
else if (input instanceof ArrayBuffer) buf = Buffer.from(input);
|
|
33
|
+
else buf = input;
|
|
34
|
+
return buf.toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
35
|
+
}
|
|
36
|
+
function sha256HashNode(data) {
|
|
37
|
+
const { createHash } = __require("crypto");
|
|
38
|
+
return createHash("sha256").update(data).digest();
|
|
39
|
+
}
|
|
40
|
+
async function hashInput(data) {
|
|
41
|
+
if (typeof window !== "undefined" && window.crypto?.subtle) {
|
|
42
|
+
const encoder = new TextEncoder();
|
|
43
|
+
const encoded = encoder.encode(data);
|
|
44
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", encoded);
|
|
45
|
+
return Buffer.from(hashBuffer);
|
|
46
|
+
} else {
|
|
47
|
+
return sha256HashNode(data);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function generateJWT(sub, aud, keyPair, expiresInSeconds = 24 * 60 * 60) {
|
|
51
|
+
const iat = Math.floor(Date.now() / 1e3);
|
|
52
|
+
const exp = iat + expiresInSeconds;
|
|
53
|
+
const header = { alg: "ES256", typ: "JWT" };
|
|
54
|
+
const payload = { sub, aud, iat, exp };
|
|
55
|
+
const encodedHeader = base64url(JSON.stringify(header));
|
|
56
|
+
const encodedPayload = base64url(JSON.stringify(payload));
|
|
57
|
+
const signingInput = `${encodedHeader}.${encodedPayload}`;
|
|
58
|
+
const hash = await hashInput(signingInput);
|
|
59
|
+
const signature = keyPair.sign(hash, { canonical: true });
|
|
60
|
+
const rBuf = signature.r.toArrayLike(Buffer, "be", 32);
|
|
61
|
+
const sBuf = signature.s.toArrayLike(Buffer, "be", 32);
|
|
62
|
+
const rawSig = Buffer.concat([rBuf, sBuf]);
|
|
63
|
+
const encodedSig = base64url(rawSig);
|
|
64
|
+
return `${signingInput}.${encodedSig}`;
|
|
65
|
+
}
|
|
66
|
+
async function createAuthEnvelope(privateKeyHex, network = "testnet" /* Testnet */, options) {
|
|
67
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
68
|
+
const publicKey = serializePublicKeyCompressed(keyPair);
|
|
69
|
+
const host = NETWORK_HOSTS[network];
|
|
70
|
+
if (!host) {
|
|
71
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
72
|
+
}
|
|
73
|
+
const token = await generateJWT(publicKey, host, keyPair, options?.expiresInSeconds);
|
|
74
|
+
return { publicKey, token };
|
|
75
|
+
}
|
|
76
|
+
async function generateAppSignature(privateKeyHex, clientId, redirectUri, state) {
|
|
77
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
78
|
+
const message = `${clientId}:${redirectUri}:${state}`;
|
|
79
|
+
const hash = await hashInput(message);
|
|
80
|
+
const signatureDER = keyPair.sign(hash, { canonical: true }).toDER();
|
|
81
|
+
return Buffer.from(signatureDER).toString("hex");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
__require,
|
|
86
|
+
Network,
|
|
87
|
+
NETWORK_HOSTS,
|
|
88
|
+
loadExistingSecp256k1PrivateKey,
|
|
89
|
+
serializePublicKeyCompressed,
|
|
90
|
+
generateJWT,
|
|
91
|
+
createAuthEnvelope,
|
|
92
|
+
generateAppSignature
|
|
93
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/helpers/CryptoUtils.tsx
|
|
9
|
+
import { ec as EC } from "elliptic";
|
|
10
|
+
var ec = new EC("secp256k1");
|
|
11
|
+
var Network = /* @__PURE__ */ ((Network2) => {
|
|
12
|
+
Network2["Testnet"] = "testnet";
|
|
13
|
+
Network2["Localnet"] = "localnet";
|
|
14
|
+
return Network2;
|
|
15
|
+
})(Network || {});
|
|
16
|
+
var NETWORK_HOSTS = {
|
|
17
|
+
["testnet" /* Testnet */]: "https://dev-db.petastic.com",
|
|
18
|
+
["localnet" /* Localnet */]: "http://docker.host.internal:9181"
|
|
19
|
+
};
|
|
20
|
+
function loadExistingSecp256k1PrivateKey(hexKey) {
|
|
21
|
+
if (!hexKey) {
|
|
22
|
+
throw new Error("Private key hex must be provided");
|
|
23
|
+
}
|
|
24
|
+
return ec.keyFromPrivate(hexKey, "hex");
|
|
25
|
+
}
|
|
26
|
+
function serializePublicKeyCompressed(keyPair) {
|
|
27
|
+
return keyPair.getPublic(true, "hex");
|
|
28
|
+
}
|
|
29
|
+
function base64url(input) {
|
|
30
|
+
let buf;
|
|
31
|
+
if (typeof input === "string") buf = Buffer.from(input);
|
|
32
|
+
else if (input instanceof ArrayBuffer) buf = Buffer.from(input);
|
|
33
|
+
else buf = input;
|
|
34
|
+
return buf.toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
35
|
+
}
|
|
36
|
+
function sha256HashNode(data) {
|
|
37
|
+
const { createHash } = __require("crypto");
|
|
38
|
+
return createHash("sha256").update(data).digest();
|
|
39
|
+
}
|
|
40
|
+
async function hashInput(data) {
|
|
41
|
+
if (typeof window !== "undefined" && window.crypto?.subtle) {
|
|
42
|
+
const encoder = new TextEncoder();
|
|
43
|
+
const encoded = encoder.encode(data);
|
|
44
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", encoded);
|
|
45
|
+
return Buffer.from(hashBuffer);
|
|
46
|
+
} else {
|
|
47
|
+
return sha256HashNode(data);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function generateJWT(sub, aud, keyPair, expiresInSeconds = 24 * 60 * 60) {
|
|
51
|
+
const iat = Math.floor(Date.now() / 1e3);
|
|
52
|
+
const exp = iat + expiresInSeconds;
|
|
53
|
+
const header = { alg: "ES256", typ: "JWT" };
|
|
54
|
+
const payload = { sub, aud, iat, exp };
|
|
55
|
+
const encodedHeader = base64url(JSON.stringify(header));
|
|
56
|
+
const encodedPayload = base64url(JSON.stringify(payload));
|
|
57
|
+
const signingInput = `${encodedHeader}.${encodedPayload}`;
|
|
58
|
+
const hash = await hashInput(signingInput);
|
|
59
|
+
const signature = keyPair.sign(hash, { canonical: true });
|
|
60
|
+
const rBuf = signature.r.toArrayLike(Buffer, "be", 32);
|
|
61
|
+
const sBuf = signature.s.toArrayLike(Buffer, "be", 32);
|
|
62
|
+
const rawSig = Buffer.concat([rBuf, sBuf]);
|
|
63
|
+
const encodedSig = base64url(rawSig);
|
|
64
|
+
return `${signingInput}.${encodedSig}`;
|
|
65
|
+
}
|
|
66
|
+
async function createAuthEnvelope(privateKeyHex, network = "testnet" /* Testnet */, options) {
|
|
67
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
68
|
+
const publicKey = serializePublicKeyCompressed(keyPair);
|
|
69
|
+
const host = NETWORK_HOSTS[network];
|
|
70
|
+
if (!host) {
|
|
71
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
72
|
+
}
|
|
73
|
+
const token = await generateJWT(publicKey, host, keyPair, options?.expiresInSeconds);
|
|
74
|
+
return { publicKey, token };
|
|
75
|
+
}
|
|
76
|
+
async function generateAppSignature(privateKeyHex, clientId, redirectUri, state) {
|
|
77
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
78
|
+
const message = `${clientId}:${redirectUri}:${state}`;
|
|
79
|
+
const hash = await hashInput(message);
|
|
80
|
+
const signatureDER = keyPair.sign(hash, { canonical: true }).toDER();
|
|
81
|
+
return Buffer.from(signatureDER).toString("hex");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
__require,
|
|
86
|
+
Network,
|
|
87
|
+
NETWORK_HOSTS,
|
|
88
|
+
loadExistingSecp256k1PrivateKey,
|
|
89
|
+
serializePublicKeyCompressed,
|
|
90
|
+
generateJWT,
|
|
91
|
+
createAuthEnvelope,
|
|
92
|
+
generateAppSignature
|
|
93
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/helpers/CryptoUtils.tsx
|
|
9
|
+
import { ec as EC } from "elliptic";
|
|
10
|
+
var ec = new EC("secp256k1");
|
|
11
|
+
var Network = /* @__PURE__ */ ((Network2) => {
|
|
12
|
+
Network2["Testnet"] = "testnet";
|
|
13
|
+
return Network2;
|
|
14
|
+
})(Network || {});
|
|
15
|
+
var NETWORK_HOSTS = {
|
|
16
|
+
["testnet" /* Testnet */]: "https://dev-db.petastic.com"
|
|
17
|
+
};
|
|
18
|
+
function loadExistingSecp256k1PrivateKey(hexKey) {
|
|
19
|
+
if (!hexKey) {
|
|
20
|
+
throw new Error("Private key hex must be provided");
|
|
21
|
+
}
|
|
22
|
+
return ec.keyFromPrivate(hexKey, "hex");
|
|
23
|
+
}
|
|
24
|
+
function serializePublicKeyCompressed(keyPair) {
|
|
25
|
+
return keyPair.getPublic(true, "hex");
|
|
26
|
+
}
|
|
27
|
+
function base64url(input) {
|
|
28
|
+
let buf;
|
|
29
|
+
if (typeof input === "string") buf = Buffer.from(input);
|
|
30
|
+
else if (input instanceof ArrayBuffer) buf = Buffer.from(input);
|
|
31
|
+
else buf = input;
|
|
32
|
+
return buf.toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
33
|
+
}
|
|
34
|
+
function sha256HashNode(data) {
|
|
35
|
+
const { createHash } = __require("crypto");
|
|
36
|
+
return createHash("sha256").update(data).digest();
|
|
37
|
+
}
|
|
38
|
+
async function hashInput(data) {
|
|
39
|
+
if (typeof window !== "undefined" && window.crypto?.subtle) {
|
|
40
|
+
const encoder = new TextEncoder();
|
|
41
|
+
const encoded = encoder.encode(data);
|
|
42
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", encoded);
|
|
43
|
+
return Buffer.from(hashBuffer);
|
|
44
|
+
} else {
|
|
45
|
+
return sha256HashNode(data);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function generateJWT(sub, aud, keyPair, expiresInSeconds = 24 * 60 * 60) {
|
|
49
|
+
const iat = Math.floor(Date.now() / 1e3);
|
|
50
|
+
const exp = iat + expiresInSeconds;
|
|
51
|
+
const header = { alg: "ES256", typ: "JWT" };
|
|
52
|
+
const payload = { sub, aud, iat, exp };
|
|
53
|
+
const encodedHeader = base64url(JSON.stringify(header));
|
|
54
|
+
const encodedPayload = base64url(JSON.stringify(payload));
|
|
55
|
+
const signingInput = `${encodedHeader}.${encodedPayload}`;
|
|
56
|
+
const hash = await hashInput(signingInput);
|
|
57
|
+
const signature = keyPair.sign(hash, { canonical: true });
|
|
58
|
+
const rBuf = signature.r.toArrayLike(Buffer, "be", 32);
|
|
59
|
+
const sBuf = signature.s.toArrayLike(Buffer, "be", 32);
|
|
60
|
+
const rawSig = Buffer.concat([rBuf, sBuf]);
|
|
61
|
+
const encodedSig = base64url(rawSig);
|
|
62
|
+
return `${signingInput}.${encodedSig}`;
|
|
63
|
+
}
|
|
64
|
+
async function createAuthEnvelope(privateKeyHex, network = "testnet" /* Testnet */, options) {
|
|
65
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
66
|
+
const publicKey = serializePublicKeyCompressed(keyPair);
|
|
67
|
+
const host = NETWORK_HOSTS[network];
|
|
68
|
+
if (!host) {
|
|
69
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
70
|
+
}
|
|
71
|
+
const token = await generateJWT(publicKey, host, keyPair, options?.expiresInSeconds);
|
|
72
|
+
return { publicKey, token };
|
|
73
|
+
}
|
|
74
|
+
async function generateAppSignature(privateKeyHex, clientId, redirectUri, state) {
|
|
75
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
76
|
+
const message = `${clientId}:${redirectUri}:${state}`;
|
|
77
|
+
const hash = await hashInput(message);
|
|
78
|
+
const signatureDER = keyPair.sign(hash, { canonical: true }).toDER();
|
|
79
|
+
return Buffer.from(signatureDER).toString("hex");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
__require,
|
|
84
|
+
Network,
|
|
85
|
+
NETWORK_HOSTS,
|
|
86
|
+
loadExistingSecp256k1PrivateKey,
|
|
87
|
+
serializePublicKeyCompressed,
|
|
88
|
+
generateJWT,
|
|
89
|
+
createAuthEnvelope,
|
|
90
|
+
generateAppSignature
|
|
91
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/helpers/CryptoUtils.tsx
|
|
9
|
+
import { ec as EC } from "elliptic";
|
|
10
|
+
var ec = new EC("secp256k1");
|
|
11
|
+
var Network = /* @__PURE__ */ ((Network2) => {
|
|
12
|
+
Network2["Testnet"] = "testnet";
|
|
13
|
+
Network2["Localnet"] = "localnet";
|
|
14
|
+
return Network2;
|
|
15
|
+
})(Network || {});
|
|
16
|
+
var NETWORK_HOSTS = {
|
|
17
|
+
["testnet" /* Testnet */]: "dev-db.petastic.com",
|
|
18
|
+
["localnet" /* Localnet */]: "host.docker.internal:9181"
|
|
19
|
+
};
|
|
20
|
+
function loadExistingSecp256k1PrivateKey(hexKey) {
|
|
21
|
+
if (!hexKey) {
|
|
22
|
+
throw new Error("Private key hex must be provided");
|
|
23
|
+
}
|
|
24
|
+
return ec.keyFromPrivate(hexKey, "hex");
|
|
25
|
+
}
|
|
26
|
+
function serializePublicKeyCompressed(keyPair) {
|
|
27
|
+
return keyPair.getPublic(true, "hex");
|
|
28
|
+
}
|
|
29
|
+
function base64url(input) {
|
|
30
|
+
let buf;
|
|
31
|
+
if (typeof input === "string") buf = Buffer.from(input);
|
|
32
|
+
else if (input instanceof ArrayBuffer) buf = Buffer.from(input);
|
|
33
|
+
else buf = input;
|
|
34
|
+
return buf.toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
35
|
+
}
|
|
36
|
+
function sha256HashNode(data) {
|
|
37
|
+
const { createHash } = __require("crypto");
|
|
38
|
+
return createHash("sha256").update(data).digest();
|
|
39
|
+
}
|
|
40
|
+
async function hashInput(data) {
|
|
41
|
+
if (typeof window !== "undefined" && window.crypto?.subtle) {
|
|
42
|
+
const encoder = new TextEncoder();
|
|
43
|
+
const encoded = encoder.encode(data);
|
|
44
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", encoded);
|
|
45
|
+
return Buffer.from(hashBuffer);
|
|
46
|
+
} else {
|
|
47
|
+
return sha256HashNode(data);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function generateJWT(sub, aud, keyPair, expiresInSeconds = 24 * 60 * 60) {
|
|
51
|
+
const iat = Math.floor(Date.now() / 1e3);
|
|
52
|
+
const exp = iat + expiresInSeconds;
|
|
53
|
+
const header = { alg: "ES256", typ: "JWT" };
|
|
54
|
+
const payload = { sub, aud, iat, exp };
|
|
55
|
+
const encodedHeader = base64url(JSON.stringify(header));
|
|
56
|
+
const encodedPayload = base64url(JSON.stringify(payload));
|
|
57
|
+
const signingInput = `${encodedHeader}.${encodedPayload}`;
|
|
58
|
+
const hash = await hashInput(signingInput);
|
|
59
|
+
const signature = keyPair.sign(hash, { canonical: true });
|
|
60
|
+
const rBuf = signature.r.toArrayLike(Buffer, "be", 32);
|
|
61
|
+
const sBuf = signature.s.toArrayLike(Buffer, "be", 32);
|
|
62
|
+
const rawSig = Buffer.concat([rBuf, sBuf]);
|
|
63
|
+
const encodedSig = base64url(rawSig);
|
|
64
|
+
return `${signingInput}.${encodedSig}`;
|
|
65
|
+
}
|
|
66
|
+
async function createAuthEnvelope(privateKeyHex, network = "testnet" /* Testnet */, options) {
|
|
67
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
68
|
+
const publicKey = serializePublicKeyCompressed(keyPair);
|
|
69
|
+
const host = NETWORK_HOSTS[network];
|
|
70
|
+
if (!host) {
|
|
71
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
72
|
+
}
|
|
73
|
+
const token = await generateJWT(publicKey, host, keyPair, options?.expiresInSeconds);
|
|
74
|
+
return { publicKey, token };
|
|
75
|
+
}
|
|
76
|
+
async function generateAppSignature(privateKeyHex, clientId, redirectUri, state) {
|
|
77
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
78
|
+
const message = `${clientId}:${redirectUri}:${state}`;
|
|
79
|
+
const hash = await hashInput(message);
|
|
80
|
+
const signatureDER = keyPair.sign(hash, { canonical: true }).toDER();
|
|
81
|
+
return Buffer.from(signatureDER).toString("hex");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
__require,
|
|
86
|
+
Network,
|
|
87
|
+
NETWORK_HOSTS,
|
|
88
|
+
loadExistingSecp256k1PrivateKey,
|
|
89
|
+
serializePublicKeyCompressed,
|
|
90
|
+
generateJWT,
|
|
91
|
+
createAuthEnvelope,
|
|
92
|
+
generateAppSignature
|
|
93
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/helpers/CryptoUtils.tsx
|
|
9
|
+
import { ec as EC } from "elliptic";
|
|
10
|
+
var ec = new EC("secp256k1");
|
|
11
|
+
var Network = /* @__PURE__ */ ((Network2) => {
|
|
12
|
+
Network2["Testnet"] = "testnet";
|
|
13
|
+
Network2["Localnet"] = "localnet";
|
|
14
|
+
return Network2;
|
|
15
|
+
})(Network || {});
|
|
16
|
+
var NETWORK_HOSTS = {
|
|
17
|
+
["testnet" /* Testnet */]: "https://dev-db.petastic.com",
|
|
18
|
+
["localnet" /* Localnet */]: "host.docker.internal:9181"
|
|
19
|
+
};
|
|
20
|
+
function loadExistingSecp256k1PrivateKey(hexKey) {
|
|
21
|
+
if (!hexKey) {
|
|
22
|
+
throw new Error("Private key hex must be provided");
|
|
23
|
+
}
|
|
24
|
+
return ec.keyFromPrivate(hexKey, "hex");
|
|
25
|
+
}
|
|
26
|
+
function serializePublicKeyCompressed(keyPair) {
|
|
27
|
+
return keyPair.getPublic(true, "hex");
|
|
28
|
+
}
|
|
29
|
+
function base64url(input) {
|
|
30
|
+
let buf;
|
|
31
|
+
if (typeof input === "string") buf = Buffer.from(input);
|
|
32
|
+
else if (input instanceof ArrayBuffer) buf = Buffer.from(input);
|
|
33
|
+
else buf = input;
|
|
34
|
+
return buf.toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
35
|
+
}
|
|
36
|
+
function sha256HashNode(data) {
|
|
37
|
+
const { createHash } = __require("crypto");
|
|
38
|
+
return createHash("sha256").update(data).digest();
|
|
39
|
+
}
|
|
40
|
+
async function hashInput(data) {
|
|
41
|
+
if (typeof window !== "undefined" && window.crypto?.subtle) {
|
|
42
|
+
const encoder = new TextEncoder();
|
|
43
|
+
const encoded = encoder.encode(data);
|
|
44
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", encoded);
|
|
45
|
+
return Buffer.from(hashBuffer);
|
|
46
|
+
} else {
|
|
47
|
+
return sha256HashNode(data);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function generateJWT(sub, aud, keyPair, expiresInSeconds = 24 * 60 * 60) {
|
|
51
|
+
const iat = Math.floor(Date.now() / 1e3);
|
|
52
|
+
const exp = iat + expiresInSeconds;
|
|
53
|
+
const header = { alg: "ES256", typ: "JWT" };
|
|
54
|
+
const payload = { sub, aud, iat, exp };
|
|
55
|
+
const encodedHeader = base64url(JSON.stringify(header));
|
|
56
|
+
const encodedPayload = base64url(JSON.stringify(payload));
|
|
57
|
+
const signingInput = `${encodedHeader}.${encodedPayload}`;
|
|
58
|
+
const hash = await hashInput(signingInput);
|
|
59
|
+
const signature = keyPair.sign(hash, { canonical: true });
|
|
60
|
+
const rBuf = signature.r.toArrayLike(Buffer, "be", 32);
|
|
61
|
+
const sBuf = signature.s.toArrayLike(Buffer, "be", 32);
|
|
62
|
+
const rawSig = Buffer.concat([rBuf, sBuf]);
|
|
63
|
+
const encodedSig = base64url(rawSig);
|
|
64
|
+
return `${signingInput}.${encodedSig}`;
|
|
65
|
+
}
|
|
66
|
+
async function createAuthEnvelope(privateKeyHex, network = "testnet" /* Testnet */, options) {
|
|
67
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
68
|
+
const publicKey = serializePublicKeyCompressed(keyPair);
|
|
69
|
+
const host = NETWORK_HOSTS[network];
|
|
70
|
+
if (!host) {
|
|
71
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
72
|
+
}
|
|
73
|
+
const token = await generateJWT(publicKey, host, keyPair, options?.expiresInSeconds);
|
|
74
|
+
return { publicKey, token };
|
|
75
|
+
}
|
|
76
|
+
async function generateAppSignature(privateKeyHex, clientId, redirectUri, state) {
|
|
77
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
78
|
+
const message = `${clientId}:${redirectUri}:${state}`;
|
|
79
|
+
const hash = await hashInput(message);
|
|
80
|
+
const signatureDER = keyPair.sign(hash, { canonical: true }).toDER();
|
|
81
|
+
return Buffer.from(signatureDER).toString("hex");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
__require,
|
|
86
|
+
Network,
|
|
87
|
+
NETWORK_HOSTS,
|
|
88
|
+
loadExistingSecp256k1PrivateKey,
|
|
89
|
+
serializePublicKeyCompressed,
|
|
90
|
+
generateJWT,
|
|
91
|
+
createAuthEnvelope,
|
|
92
|
+
generateAppSignature
|
|
93
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1266,6 +1266,44 @@ var ORGANIZATION_IMPL_ABI = [
|
|
|
1266
1266
|
|
|
1267
1267
|
// src/utils/anymals/useMintAnymalNFT.ts
|
|
1268
1268
|
var import_react10 = require("react");
|
|
1269
|
+
|
|
1270
|
+
// src/helpers/GasEstimateHelper.tsx
|
|
1271
|
+
function applyBundlerGasEstimator(account, bundlerClient, options) {
|
|
1272
|
+
const {
|
|
1273
|
+
callGasMultiplier = 1.2,
|
|
1274
|
+
verificationGasMultiplier = 1.2,
|
|
1275
|
+
preVerificationGasMultiplier = 2,
|
|
1276
|
+
debug = true
|
|
1277
|
+
} = options || {};
|
|
1278
|
+
account.userOperation = {
|
|
1279
|
+
estimateGas: async (userOp) => {
|
|
1280
|
+
const estimate = await bundlerClient.estimateUserOperationGas(userOp);
|
|
1281
|
+
const paddedCallGasLimit = BigInt(
|
|
1282
|
+
estimate.callGasLimit * BigInt(Math.ceil(callGasMultiplier * 100)) / 100n
|
|
1283
|
+
);
|
|
1284
|
+
const paddedVerificationGasLimit = BigInt(
|
|
1285
|
+
estimate.verificationGasLimit * BigInt(Math.ceil(verificationGasMultiplier * 100)) / 100n
|
|
1286
|
+
);
|
|
1287
|
+
const paddedPreVerificationGas = BigInt(
|
|
1288
|
+
estimate.preVerificationGas * BigInt(Math.ceil(preVerificationGasMultiplier * 100)) / 100n
|
|
1289
|
+
);
|
|
1290
|
+
if (debug) {
|
|
1291
|
+
console.log("\u{1F4E6} Bundler Gas Estimates:");
|
|
1292
|
+
console.log(" callGasLimit:", paddedCallGasLimit.toString());
|
|
1293
|
+
console.log(" verificationGasLimit:", paddedVerificationGasLimit.toString());
|
|
1294
|
+
console.log(" preVerificationGas:", paddedPreVerificationGas.toString());
|
|
1295
|
+
}
|
|
1296
|
+
return {
|
|
1297
|
+
...estimate,
|
|
1298
|
+
callGasLimit: paddedCallGasLimit,
|
|
1299
|
+
verificationGasLimit: paddedVerificationGasLimit,
|
|
1300
|
+
preVerificationGas: paddedPreVerificationGas
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
// src/utils/anymals/useMintAnymalNFT.ts
|
|
1269
1307
|
function useMintAnymalNFT() {
|
|
1270
1308
|
return (0, import_react10.useCallback)(
|
|
1271
1309
|
async (pid, nftId, anymalTxId, dbAuthToken, validationContractAddress, smartAccount, bundlerClient) => {
|
|
@@ -1286,6 +1324,7 @@ function useMintAnymalNFT() {
|
|
|
1286
1324
|
anymalTxId
|
|
1287
1325
|
]
|
|
1288
1326
|
});
|
|
1327
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1289
1328
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1290
1329
|
account: smartAccount,
|
|
1291
1330
|
calls: [
|
|
@@ -1714,6 +1753,7 @@ function useProcessPartialKibblePayment() {
|
|
|
1714
1753
|
functionName: "partialPay",
|
|
1715
1754
|
args
|
|
1716
1755
|
});
|
|
1756
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1717
1757
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1718
1758
|
account: smartAccount,
|
|
1719
1759
|
calls: [
|
|
@@ -1759,6 +1799,7 @@ function useApproveKibbleToken() {
|
|
|
1759
1799
|
// amount to approve
|
|
1760
1800
|
]
|
|
1761
1801
|
});
|
|
1802
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1762
1803
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1763
1804
|
account: smartAccount,
|
|
1764
1805
|
calls: [
|
|
@@ -1820,6 +1861,7 @@ function useCreateOrganizationBase() {
|
|
|
1820
1861
|
functionName: "createOrganizationProxy",
|
|
1821
1862
|
args: [ownerAddress, orgName, orgPid]
|
|
1822
1863
|
});
|
|
1864
|
+
applyBundlerGasEstimator(adminSmartAccount, bundlerClient);
|
|
1823
1865
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1824
1866
|
account: adminSmartAccount,
|
|
1825
1867
|
calls: [
|
|
@@ -1828,9 +1870,7 @@ function useCreateOrganizationBase() {
|
|
|
1828
1870
|
data: callData
|
|
1829
1871
|
}
|
|
1830
1872
|
],
|
|
1831
|
-
|
|
1832
|
-
// Low priority fee
|
|
1833
|
-
// maxFeePerGas: parseGwei("0.15"), // Max fee cap -- keeps rising at random
|
|
1873
|
+
paymaster: true
|
|
1834
1874
|
});
|
|
1835
1875
|
const txReceipt = await bundlerClient.waitForUserOperationReceipt({
|
|
1836
1876
|
hash: userOpHash,
|
|
@@ -1873,7 +1913,7 @@ function useCreateOrganizationBase() {
|
|
|
1873
1913
|
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
|
|
1874
1914
|
return {
|
|
1875
1915
|
success: false,
|
|
1876
|
-
message: `Error processing organization: ${errorMessage}`
|
|
1916
|
+
message: `Error processing organization here: ${errorMessage}`
|
|
1877
1917
|
};
|
|
1878
1918
|
}
|
|
1879
1919
|
},
|
|
@@ -1904,6 +1944,7 @@ function useApproveOrgPartialPayment() {
|
|
|
1904
1944
|
functionName: "executeCall",
|
|
1905
1945
|
args: [kibbleTokenAddress, approveCalldata]
|
|
1906
1946
|
});
|
|
1947
|
+
applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
|
|
1907
1948
|
const userOpApproveHash = await bundlerClient.sendUserOperation({
|
|
1908
1949
|
account: managerSmartAccount,
|
|
1909
1950
|
calls: [
|
|
@@ -1963,6 +2004,7 @@ function useProcessOrgPartialKibblePayment() {
|
|
|
1963
2004
|
functionName: "executeCall",
|
|
1964
2005
|
args: [partialPaymentModuleAddress, partialPayCalldata]
|
|
1965
2006
|
});
|
|
2007
|
+
applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
|
|
1966
2008
|
const userOpPartialPayHash = await bundlerClient.sendUserOperation({
|
|
1967
2009
|
account: managerSmartAccount,
|
|
1968
2010
|
calls: [
|
|
@@ -2426,6 +2468,7 @@ function useClaimActionReward() {
|
|
|
2426
2468
|
functionName: "claimByIndex",
|
|
2427
2469
|
args: [actionId, claimIndex]
|
|
2428
2470
|
});
|
|
2471
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
2429
2472
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
2430
2473
|
account: smartAccount,
|
|
2431
2474
|
calls: [
|
|
@@ -2469,6 +2512,7 @@ function useClaimOrgActionReward() {
|
|
|
2469
2512
|
functionName: "executeCall",
|
|
2470
2513
|
args: [rewardableActionContractAddress, claimCallData]
|
|
2471
2514
|
});
|
|
2515
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
2472
2516
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
2473
2517
|
account: smartAccount,
|
|
2474
2518
|
calls: [
|
package/dist/index.mjs
CHANGED
|
@@ -1203,6 +1203,44 @@ var ORGANIZATION_IMPL_ABI = [
|
|
|
1203
1203
|
|
|
1204
1204
|
// src/utils/anymals/useMintAnymalNFT.ts
|
|
1205
1205
|
import { useCallback as useCallback10 } from "react";
|
|
1206
|
+
|
|
1207
|
+
// src/helpers/GasEstimateHelper.tsx
|
|
1208
|
+
function applyBundlerGasEstimator(account, bundlerClient, options) {
|
|
1209
|
+
const {
|
|
1210
|
+
callGasMultiplier = 1.2,
|
|
1211
|
+
verificationGasMultiplier = 1.2,
|
|
1212
|
+
preVerificationGasMultiplier = 2,
|
|
1213
|
+
debug = true
|
|
1214
|
+
} = options || {};
|
|
1215
|
+
account.userOperation = {
|
|
1216
|
+
estimateGas: async (userOp) => {
|
|
1217
|
+
const estimate = await bundlerClient.estimateUserOperationGas(userOp);
|
|
1218
|
+
const paddedCallGasLimit = BigInt(
|
|
1219
|
+
estimate.callGasLimit * BigInt(Math.ceil(callGasMultiplier * 100)) / 100n
|
|
1220
|
+
);
|
|
1221
|
+
const paddedVerificationGasLimit = BigInt(
|
|
1222
|
+
estimate.verificationGasLimit * BigInt(Math.ceil(verificationGasMultiplier * 100)) / 100n
|
|
1223
|
+
);
|
|
1224
|
+
const paddedPreVerificationGas = BigInt(
|
|
1225
|
+
estimate.preVerificationGas * BigInt(Math.ceil(preVerificationGasMultiplier * 100)) / 100n
|
|
1226
|
+
);
|
|
1227
|
+
if (debug) {
|
|
1228
|
+
console.log("\u{1F4E6} Bundler Gas Estimates:");
|
|
1229
|
+
console.log(" callGasLimit:", paddedCallGasLimit.toString());
|
|
1230
|
+
console.log(" verificationGasLimit:", paddedVerificationGasLimit.toString());
|
|
1231
|
+
console.log(" preVerificationGas:", paddedPreVerificationGas.toString());
|
|
1232
|
+
}
|
|
1233
|
+
return {
|
|
1234
|
+
...estimate,
|
|
1235
|
+
callGasLimit: paddedCallGasLimit,
|
|
1236
|
+
verificationGasLimit: paddedVerificationGasLimit,
|
|
1237
|
+
preVerificationGas: paddedPreVerificationGas
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
// src/utils/anymals/useMintAnymalNFT.ts
|
|
1206
1244
|
function useMintAnymalNFT() {
|
|
1207
1245
|
return useCallback10(
|
|
1208
1246
|
async (pid, nftId, anymalTxId, dbAuthToken, validationContractAddress, smartAccount, bundlerClient) => {
|
|
@@ -1223,6 +1261,7 @@ function useMintAnymalNFT() {
|
|
|
1223
1261
|
anymalTxId
|
|
1224
1262
|
]
|
|
1225
1263
|
});
|
|
1264
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1226
1265
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1227
1266
|
account: smartAccount,
|
|
1228
1267
|
calls: [
|
|
@@ -1651,6 +1690,7 @@ function useProcessPartialKibblePayment() {
|
|
|
1651
1690
|
functionName: "partialPay",
|
|
1652
1691
|
args
|
|
1653
1692
|
});
|
|
1693
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1654
1694
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1655
1695
|
account: smartAccount,
|
|
1656
1696
|
calls: [
|
|
@@ -1696,6 +1736,7 @@ function useApproveKibbleToken() {
|
|
|
1696
1736
|
// amount to approve
|
|
1697
1737
|
]
|
|
1698
1738
|
});
|
|
1739
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
1699
1740
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1700
1741
|
account: smartAccount,
|
|
1701
1742
|
calls: [
|
|
@@ -1730,7 +1771,7 @@ function useApproveKibbleToken() {
|
|
|
1730
1771
|
|
|
1731
1772
|
// src/utils/organization/useCreateOrganizationBase.ts
|
|
1732
1773
|
import { useCallback as useCallback19 } from "react";
|
|
1733
|
-
import { decodeEventLog, encodeFunctionData as encodeFunctionData4
|
|
1774
|
+
import { decodeEventLog, encodeFunctionData as encodeFunctionData4 } from "viem";
|
|
1734
1775
|
function useCreateOrganizationBase() {
|
|
1735
1776
|
return useCallback19(
|
|
1736
1777
|
/**
|
|
@@ -1757,6 +1798,7 @@ function useCreateOrganizationBase() {
|
|
|
1757
1798
|
functionName: "createOrganizationProxy",
|
|
1758
1799
|
args: [ownerAddress, orgName, orgPid]
|
|
1759
1800
|
});
|
|
1801
|
+
applyBundlerGasEstimator(adminSmartAccount, bundlerClient);
|
|
1760
1802
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
1761
1803
|
account: adminSmartAccount,
|
|
1762
1804
|
calls: [
|
|
@@ -1765,9 +1807,7 @@ function useCreateOrganizationBase() {
|
|
|
1765
1807
|
data: callData
|
|
1766
1808
|
}
|
|
1767
1809
|
],
|
|
1768
|
-
|
|
1769
|
-
// Low priority fee
|
|
1770
|
-
// maxFeePerGas: parseGwei("0.15"), // Max fee cap -- keeps rising at random
|
|
1810
|
+
paymaster: true
|
|
1771
1811
|
});
|
|
1772
1812
|
const txReceipt = await bundlerClient.waitForUserOperationReceipt({
|
|
1773
1813
|
hash: userOpHash,
|
|
@@ -1810,7 +1850,7 @@ function useCreateOrganizationBase() {
|
|
|
1810
1850
|
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred.";
|
|
1811
1851
|
return {
|
|
1812
1852
|
success: false,
|
|
1813
|
-
message: `Error processing organization: ${errorMessage}`
|
|
1853
|
+
message: `Error processing organization here: ${errorMessage}`
|
|
1814
1854
|
};
|
|
1815
1855
|
}
|
|
1816
1856
|
},
|
|
@@ -1841,6 +1881,7 @@ function useApproveOrgPartialPayment() {
|
|
|
1841
1881
|
functionName: "executeCall",
|
|
1842
1882
|
args: [kibbleTokenAddress, approveCalldata]
|
|
1843
1883
|
});
|
|
1884
|
+
applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
|
|
1844
1885
|
const userOpApproveHash = await bundlerClient.sendUserOperation({
|
|
1845
1886
|
account: managerSmartAccount,
|
|
1846
1887
|
calls: [
|
|
@@ -1900,6 +1941,7 @@ function useProcessOrgPartialKibblePayment() {
|
|
|
1900
1941
|
functionName: "executeCall",
|
|
1901
1942
|
args: [partialPaymentModuleAddress, partialPayCalldata]
|
|
1902
1943
|
});
|
|
1944
|
+
applyBundlerGasEstimator(managerSmartAccount, bundlerClient);
|
|
1903
1945
|
const userOpPartialPayHash = await bundlerClient.sendUserOperation({
|
|
1904
1946
|
account: managerSmartAccount,
|
|
1905
1947
|
calls: [
|
|
@@ -2283,6 +2325,7 @@ function useClaimActionReward() {
|
|
|
2283
2325
|
functionName: "claimByIndex",
|
|
2284
2326
|
args: [actionId, claimIndex]
|
|
2285
2327
|
});
|
|
2328
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
2286
2329
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
2287
2330
|
account: smartAccount,
|
|
2288
2331
|
calls: [
|
|
@@ -2326,6 +2369,7 @@ function useClaimOrgActionReward() {
|
|
|
2326
2369
|
functionName: "executeCall",
|
|
2327
2370
|
args: [rewardableActionContractAddress, claimCallData]
|
|
2328
2371
|
});
|
|
2372
|
+
applyBundlerGasEstimator(smartAccount, bundlerClient);
|
|
2329
2373
|
const userOpHash = await bundlerClient.sendUserOperation({
|
|
2330
2374
|
account: smartAccount,
|
|
2331
2375
|
calls: [
|
package/package.json
CHANGED