anymal-protocol 1.0.81 → 1.0.83
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.d.mts +29 -3
- package/dist/index.d.ts +29 -3
- package/dist/index.js +9 -0
- package/dist/index.mjs +8 -0
- 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.d.mts
CHANGED
|
@@ -221,7 +221,9 @@ declare function generateAppSignature(privateKeyHex: string, clientId: string, r
|
|
|
221
221
|
declare enum ActionType {
|
|
222
222
|
GRAPHQL = "GRAPHQL",
|
|
223
223
|
CONTRACT = "CONTRACT",
|
|
224
|
-
EXTERNAL = "EXTERNAL"
|
|
224
|
+
EXTERNAL = "EXTERNAL",
|
|
225
|
+
PURCHASE = "PURCHASE",
|
|
226
|
+
WISHLIST_PURCHASE = "WISHLIST_PURCHASE"
|
|
225
227
|
}
|
|
226
228
|
/**
|
|
227
229
|
* The source type
|
|
@@ -238,6 +240,13 @@ declare enum ActionStatus {
|
|
|
238
240
|
CLAIMED = "CLAIMED",
|
|
239
241
|
REJECTED = "REJECTED"
|
|
240
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* How the marketplace item can be verified, stripe transaction, anymal transaction, etc
|
|
245
|
+
*/
|
|
246
|
+
declare enum MarketplacePaymentType {
|
|
247
|
+
STRIPE = "STRIPE",
|
|
248
|
+
ANYMAL = "ANYMAL"
|
|
249
|
+
}
|
|
241
250
|
/**
|
|
242
251
|
* Represents a single action record returned by the backend.
|
|
243
252
|
*/
|
|
@@ -324,6 +333,23 @@ interface ContractActionPayload extends BaseActionPayload {
|
|
|
324
333
|
gasUsed: string;
|
|
325
334
|
};
|
|
326
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Payload for marketplace action
|
|
338
|
+
*/
|
|
339
|
+
interface MarketplaceActionPayload extends BaseActionPayload {
|
|
340
|
+
orderId: string;
|
|
341
|
+
totalSpent: number;
|
|
342
|
+
paymentTxId: string;
|
|
343
|
+
paymentSource: MarketplacePaymentType;
|
|
344
|
+
kibblePaymentTxId: string;
|
|
345
|
+
lineItems?: any[];
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Payload for a wishlist purchase. same as a marketplace purchase except requires a wishlistId
|
|
349
|
+
*/
|
|
350
|
+
interface WishlistPurchaseActionPayload extends MarketplaceActionPayload {
|
|
351
|
+
wishlistId: string;
|
|
352
|
+
}
|
|
327
353
|
/**
|
|
328
354
|
* Payload for external web-service actions
|
|
329
355
|
*/
|
|
@@ -334,7 +360,7 @@ interface ExternalActionPayload extends BaseActionPayload {
|
|
|
334
360
|
responseStatus?: number;
|
|
335
361
|
responseBody?: any;
|
|
336
362
|
}
|
|
337
|
-
type ActionPayload = GraphQLActionPayload | ContractActionPayload | ExternalActionPayload;
|
|
363
|
+
type ActionPayload = GraphQLActionPayload | ContractActionPayload | ExternalActionPayload | MarketplaceActionPayload | WishlistPurchaseActionPayload;
|
|
338
364
|
interface SubmitResponse {
|
|
339
365
|
ok: boolean;
|
|
340
366
|
id: string;
|
|
@@ -370,4 +396,4 @@ declare function useClaimOrgActionReward(): (orgContractAddress: string, rewarda
|
|
|
370
396
|
message: string;
|
|
371
397
|
}>;
|
|
372
398
|
|
|
373
|
-
export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, type ExternalActionPayload, type GraphQLActionPayload, type JWTOptions, NETWORK_HOSTS, Network, type SubmitResponse, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
|
|
399
|
+
export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, type ExternalActionPayload, type GraphQLActionPayload, type JWTOptions, type MarketplaceActionPayload, MarketplacePaymentType, NETWORK_HOSTS, Network, type SubmitResponse, type WishlistPurchaseActionPayload, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -221,7 +221,9 @@ declare function generateAppSignature(privateKeyHex: string, clientId: string, r
|
|
|
221
221
|
declare enum ActionType {
|
|
222
222
|
GRAPHQL = "GRAPHQL",
|
|
223
223
|
CONTRACT = "CONTRACT",
|
|
224
|
-
EXTERNAL = "EXTERNAL"
|
|
224
|
+
EXTERNAL = "EXTERNAL",
|
|
225
|
+
PURCHASE = "PURCHASE",
|
|
226
|
+
WISHLIST_PURCHASE = "WISHLIST_PURCHASE"
|
|
225
227
|
}
|
|
226
228
|
/**
|
|
227
229
|
* The source type
|
|
@@ -238,6 +240,13 @@ declare enum ActionStatus {
|
|
|
238
240
|
CLAIMED = "CLAIMED",
|
|
239
241
|
REJECTED = "REJECTED"
|
|
240
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* How the marketplace item can be verified, stripe transaction, anymal transaction, etc
|
|
245
|
+
*/
|
|
246
|
+
declare enum MarketplacePaymentType {
|
|
247
|
+
STRIPE = "STRIPE",
|
|
248
|
+
ANYMAL = "ANYMAL"
|
|
249
|
+
}
|
|
241
250
|
/**
|
|
242
251
|
* Represents a single action record returned by the backend.
|
|
243
252
|
*/
|
|
@@ -324,6 +333,23 @@ interface ContractActionPayload extends BaseActionPayload {
|
|
|
324
333
|
gasUsed: string;
|
|
325
334
|
};
|
|
326
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Payload for marketplace action
|
|
338
|
+
*/
|
|
339
|
+
interface MarketplaceActionPayload extends BaseActionPayload {
|
|
340
|
+
orderId: string;
|
|
341
|
+
totalSpent: number;
|
|
342
|
+
paymentTxId: string;
|
|
343
|
+
paymentSource: MarketplacePaymentType;
|
|
344
|
+
kibblePaymentTxId: string;
|
|
345
|
+
lineItems?: any[];
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Payload for a wishlist purchase. same as a marketplace purchase except requires a wishlistId
|
|
349
|
+
*/
|
|
350
|
+
interface WishlistPurchaseActionPayload extends MarketplaceActionPayload {
|
|
351
|
+
wishlistId: string;
|
|
352
|
+
}
|
|
327
353
|
/**
|
|
328
354
|
* Payload for external web-service actions
|
|
329
355
|
*/
|
|
@@ -334,7 +360,7 @@ interface ExternalActionPayload extends BaseActionPayload {
|
|
|
334
360
|
responseStatus?: number;
|
|
335
361
|
responseBody?: any;
|
|
336
362
|
}
|
|
337
|
-
type ActionPayload = GraphQLActionPayload | ContractActionPayload | ExternalActionPayload;
|
|
363
|
+
type ActionPayload = GraphQLActionPayload | ContractActionPayload | ExternalActionPayload | MarketplaceActionPayload | WishlistPurchaseActionPayload;
|
|
338
364
|
interface SubmitResponse {
|
|
339
365
|
ok: boolean;
|
|
340
366
|
id: string;
|
|
@@ -370,4 +396,4 @@ declare function useClaimOrgActionReward(): (orgContractAddress: string, rewarda
|
|
|
370
396
|
message: string;
|
|
371
397
|
}>;
|
|
372
398
|
|
|
373
|
-
export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, type ExternalActionPayload, type GraphQLActionPayload, type JWTOptions, NETWORK_HOSTS, Network, type SubmitResponse, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
|
|
399
|
+
export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, type ExternalActionPayload, type GraphQLActionPayload, type JWTOptions, type MarketplaceActionPayload, MarketplacePaymentType, NETWORK_HOSTS, Network, type SubmitResponse, type WishlistPurchaseActionPayload, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(index_exports, {
|
|
|
24
24
|
ActionSourceType: () => ActionSourceType,
|
|
25
25
|
ActionStatus: () => ActionStatus,
|
|
26
26
|
ActionType: () => ActionType,
|
|
27
|
+
MarketplacePaymentType: () => MarketplacePaymentType,
|
|
27
28
|
NETWORK_HOSTS: () => NETWORK_HOSTS,
|
|
28
29
|
Network: () => Network,
|
|
29
30
|
createAuthEnvelope: () => createAuthEnvelope,
|
|
@@ -2195,6 +2196,8 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
|
|
|
2195
2196
|
ActionType2["GRAPHQL"] = "GRAPHQL";
|
|
2196
2197
|
ActionType2["CONTRACT"] = "CONTRACT";
|
|
2197
2198
|
ActionType2["EXTERNAL"] = "EXTERNAL";
|
|
2199
|
+
ActionType2["PURCHASE"] = "PURCHASE";
|
|
2200
|
+
ActionType2["WISHLIST_PURCHASE"] = "WISHLIST_PURCHASE";
|
|
2198
2201
|
return ActionType2;
|
|
2199
2202
|
})(ActionType || {});
|
|
2200
2203
|
var ActionSourceType = /* @__PURE__ */ ((ActionSourceType2) => {
|
|
@@ -2211,6 +2214,11 @@ var ActionStatus = /* @__PURE__ */ ((ActionStatus2) => {
|
|
|
2211
2214
|
ActionStatus2["REJECTED"] = "REJECTED";
|
|
2212
2215
|
return ActionStatus2;
|
|
2213
2216
|
})(ActionStatus || {});
|
|
2217
|
+
var MarketplacePaymentType = /* @__PURE__ */ ((MarketplacePaymentType2) => {
|
|
2218
|
+
MarketplacePaymentType2["STRIPE"] = "STRIPE";
|
|
2219
|
+
MarketplacePaymentType2["ANYMAL"] = "ANYMAL";
|
|
2220
|
+
return MarketplacePaymentType2;
|
|
2221
|
+
})(MarketplacePaymentType || {});
|
|
2214
2222
|
|
|
2215
2223
|
// src/utils/application/useCreateUserAppData.ts
|
|
2216
2224
|
var import_react25 = require("react");
|
|
@@ -2435,6 +2443,7 @@ function useClaimOrgActionReward() {
|
|
|
2435
2443
|
ActionSourceType,
|
|
2436
2444
|
ActionStatus,
|
|
2437
2445
|
ActionType,
|
|
2446
|
+
MarketplacePaymentType,
|
|
2438
2447
|
NETWORK_HOSTS,
|
|
2439
2448
|
Network,
|
|
2440
2449
|
createAuthEnvelope,
|
package/dist/index.mjs
CHANGED
|
@@ -2058,6 +2058,8 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
|
|
|
2058
2058
|
ActionType2["GRAPHQL"] = "GRAPHQL";
|
|
2059
2059
|
ActionType2["CONTRACT"] = "CONTRACT";
|
|
2060
2060
|
ActionType2["EXTERNAL"] = "EXTERNAL";
|
|
2061
|
+
ActionType2["PURCHASE"] = "PURCHASE";
|
|
2062
|
+
ActionType2["WISHLIST_PURCHASE"] = "WISHLIST_PURCHASE";
|
|
2061
2063
|
return ActionType2;
|
|
2062
2064
|
})(ActionType || {});
|
|
2063
2065
|
var ActionSourceType = /* @__PURE__ */ ((ActionSourceType2) => {
|
|
@@ -2074,6 +2076,11 @@ var ActionStatus = /* @__PURE__ */ ((ActionStatus2) => {
|
|
|
2074
2076
|
ActionStatus2["REJECTED"] = "REJECTED";
|
|
2075
2077
|
return ActionStatus2;
|
|
2076
2078
|
})(ActionStatus || {});
|
|
2079
|
+
var MarketplacePaymentType = /* @__PURE__ */ ((MarketplacePaymentType2) => {
|
|
2080
|
+
MarketplacePaymentType2["STRIPE"] = "STRIPE";
|
|
2081
|
+
MarketplacePaymentType2["ANYMAL"] = "ANYMAL";
|
|
2082
|
+
return MarketplacePaymentType2;
|
|
2083
|
+
})(MarketplacePaymentType || {});
|
|
2077
2084
|
|
|
2078
2085
|
// src/utils/application/useCreateUserAppData.ts
|
|
2079
2086
|
import { useCallback as useCallback25 } from "react";
|
|
@@ -2297,6 +2304,7 @@ export {
|
|
|
2297
2304
|
ActionSourceType,
|
|
2298
2305
|
ActionStatus,
|
|
2299
2306
|
ActionType,
|
|
2307
|
+
MarketplacePaymentType,
|
|
2300
2308
|
NETWORK_HOSTS,
|
|
2301
2309
|
Network,
|
|
2302
2310
|
createAuthEnvelope,
|
package/package.json
CHANGED