anymal-protocol 1.0.122 → 1.0.123
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-F72KTNHS.mjs +98 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -3
- package/dist/index.mjs +2 -3
- package/package.json +1 -1
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
var AUTH_API_ENDPOINTS = {
|
|
21
|
+
["testnet" /* Testnet */]: "https://dev-auth-api.petastic.com",
|
|
22
|
+
["localnet" /* Localnet */]: "http://localhost:3005"
|
|
23
|
+
};
|
|
24
|
+
function loadExistingSecp256k1PrivateKey(hexKey) {
|
|
25
|
+
if (!hexKey) {
|
|
26
|
+
throw new Error("Private key hex must be provided");
|
|
27
|
+
}
|
|
28
|
+
return ec.keyFromPrivate(hexKey, "hex");
|
|
29
|
+
}
|
|
30
|
+
function serializePublicKeyCompressed(keyPair) {
|
|
31
|
+
return keyPair.getPublic(true, "hex");
|
|
32
|
+
}
|
|
33
|
+
function base64url(input) {
|
|
34
|
+
let buf;
|
|
35
|
+
if (typeof input === "string") buf = Buffer.from(input);
|
|
36
|
+
else if (input instanceof ArrayBuffer) buf = Buffer.from(input);
|
|
37
|
+
else buf = input;
|
|
38
|
+
return buf.toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
39
|
+
}
|
|
40
|
+
function sha256HashNode(data) {
|
|
41
|
+
const { createHash } = __require("crypto");
|
|
42
|
+
return createHash("sha256").update(data).digest();
|
|
43
|
+
}
|
|
44
|
+
async function hashInput(data) {
|
|
45
|
+
if (typeof window !== "undefined" && window.crypto?.subtle) {
|
|
46
|
+
const encoder = new TextEncoder();
|
|
47
|
+
const encoded = encoder.encode(data);
|
|
48
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", encoded);
|
|
49
|
+
return Buffer.from(hashBuffer);
|
|
50
|
+
} else {
|
|
51
|
+
return sha256HashNode(data);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function generateJWT(sub, aud, keyPair, expiresInSeconds = 24 * 60 * 60) {
|
|
55
|
+
const iat = Math.floor(Date.now() / 1e3);
|
|
56
|
+
const exp = iat + expiresInSeconds;
|
|
57
|
+
const header = { alg: "ES256", typ: "JWT" };
|
|
58
|
+
const payload = { sub, aud, iat, exp };
|
|
59
|
+
const encodedHeader = base64url(JSON.stringify(header));
|
|
60
|
+
const encodedPayload = base64url(JSON.stringify(payload));
|
|
61
|
+
const signingInput = `${encodedHeader}.${encodedPayload}`;
|
|
62
|
+
const hash = await hashInput(signingInput);
|
|
63
|
+
const signature = keyPair.sign(hash, { canonical: true });
|
|
64
|
+
const rBuf = signature.r.toArrayLike(Buffer, "be", 32);
|
|
65
|
+
const sBuf = signature.s.toArrayLike(Buffer, "be", 32);
|
|
66
|
+
const rawSig = Buffer.concat([rBuf, sBuf]);
|
|
67
|
+
const encodedSig = base64url(rawSig);
|
|
68
|
+
return `${signingInput}.${encodedSig}`;
|
|
69
|
+
}
|
|
70
|
+
async function createAuthEnvelope(privateKeyHex, network = "testnet" /* Testnet */, options) {
|
|
71
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
72
|
+
const publicKey = serializePublicKeyCompressed(keyPair);
|
|
73
|
+
const host = NETWORK_HOSTS[network];
|
|
74
|
+
if (!host) {
|
|
75
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
76
|
+
}
|
|
77
|
+
const token = await generateJWT(publicKey, host, keyPair, options?.expiresInSeconds);
|
|
78
|
+
return { publicKey, token };
|
|
79
|
+
}
|
|
80
|
+
async function generateAppSignature(privateKeyHex, clientId, redirectUri, state) {
|
|
81
|
+
const keyPair = loadExistingSecp256k1PrivateKey(privateKeyHex);
|
|
82
|
+
const message = `${clientId}:${redirectUri}:${state}`;
|
|
83
|
+
const hash = await hashInput(message);
|
|
84
|
+
const signatureDER = keyPair.sign(hash, { canonical: true }).toDER();
|
|
85
|
+
return Buffer.from(signatureDER).toString("hex");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
__require,
|
|
90
|
+
Network,
|
|
91
|
+
NETWORK_HOSTS,
|
|
92
|
+
AUTH_API_ENDPOINTS,
|
|
93
|
+
loadExistingSecp256k1PrivateKey,
|
|
94
|
+
serializePublicKeyCompressed,
|
|
95
|
+
generateJWT,
|
|
96
|
+
createAuthEnvelope,
|
|
97
|
+
generateAppSignature
|
|
98
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -8,7 +8,7 @@ declare function useVerifyAccount(): (pid: string, campaignId: string, dbAuthTok
|
|
|
8
8
|
|
|
9
9
|
declare function useVerifyWeb3AuthSession(): (idToken: string, publicKey: string, authServiceBaseUrl: string) => Promise<any>;
|
|
10
10
|
|
|
11
|
-
declare function useCreateWeb3Account(): (
|
|
11
|
+
declare function useCreateWeb3Account(): (authToken: string, userPid: string, authServiceBaseUrl: string, baseWalletAddress: string, requestedContext: string) => Promise<any>;
|
|
12
12
|
|
|
13
13
|
declare function useFetchUserData(): (dbAuthToken: string, endpoint: string, pid: string) => Promise<any>;
|
|
14
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare function useVerifyAccount(): (pid: string, campaignId: string, dbAuthTok
|
|
|
8
8
|
|
|
9
9
|
declare function useVerifyWeb3AuthSession(): (idToken: string, publicKey: string, authServiceBaseUrl: string) => Promise<any>;
|
|
10
10
|
|
|
11
|
-
declare function useCreateWeb3Account(): (
|
|
11
|
+
declare function useCreateWeb3Account(): (authToken: string, userPid: string, authServiceBaseUrl: string, baseWalletAddress: string, requestedContext: string) => Promise<any>;
|
|
12
12
|
|
|
13
13
|
declare function useFetchUserData(): (dbAuthToken: string, endpoint: string, pid: string) => Promise<any>;
|
|
14
14
|
|
package/dist/index.js
CHANGED
|
@@ -136,16 +136,15 @@ function useVerifyWeb3AuthSession() {
|
|
|
136
136
|
var import_react3 = require("react");
|
|
137
137
|
function useCreateWeb3Account() {
|
|
138
138
|
return (0, import_react3.useCallback)(
|
|
139
|
-
async (
|
|
139
|
+
async (authToken, userPid, authServiceBaseUrl, baseWalletAddress, requestedContext) => {
|
|
140
140
|
try {
|
|
141
141
|
const response = await fetch(`${authServiceBaseUrl}/create-account`, {
|
|
142
142
|
method: "POST",
|
|
143
143
|
headers: {
|
|
144
144
|
"Content-Type": "application/json",
|
|
145
|
-
Authorization: "Bearer " +
|
|
145
|
+
Authorization: "Bearer " + authToken
|
|
146
146
|
},
|
|
147
147
|
body: JSON.stringify({
|
|
148
|
-
appPubKey: publicKey,
|
|
149
148
|
pid: userPid,
|
|
150
149
|
baseWalletAddress,
|
|
151
150
|
requestedContext
|
package/dist/index.mjs
CHANGED
|
@@ -64,16 +64,15 @@ function useVerifyWeb3AuthSession() {
|
|
|
64
64
|
import { useCallback as useCallback3 } from "react";
|
|
65
65
|
function useCreateWeb3Account() {
|
|
66
66
|
return useCallback3(
|
|
67
|
-
async (
|
|
67
|
+
async (authToken, userPid, authServiceBaseUrl, baseWalletAddress, requestedContext) => {
|
|
68
68
|
try {
|
|
69
69
|
const response = await fetch(`${authServiceBaseUrl}/create-account`, {
|
|
70
70
|
method: "POST",
|
|
71
71
|
headers: {
|
|
72
72
|
"Content-Type": "application/json",
|
|
73
|
-
Authorization: "Bearer " +
|
|
73
|
+
Authorization: "Bearer " + authToken
|
|
74
74
|
},
|
|
75
75
|
body: JSON.stringify({
|
|
76
|
-
appPubKey: publicKey,
|
|
77
76
|
pid: userPid,
|
|
78
77
|
baseWalletAddress,
|
|
79
78
|
requestedContext
|
package/package.json
CHANGED