anymal-protocol 1.0.102 → 1.0.103
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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -25
- package/dist/index.mjs +27 -25
- package/package.json +1 -1
- package/dist/chunk-43I5M7QS.mjs +0 -93
- package/dist/chunk-5UXBNDDZ.mjs +0 -93
- package/dist/chunk-DIGESQEI.mjs +0 -91
- package/dist/chunk-KEC6WLEL.mjs +0 -93
- package/dist/chunk-QHK3YPLJ.mjs +0 -93
package/dist/index.d.mts
CHANGED
|
@@ -10,7 +10,7 @@ declare function useVerifyWeb3AuthSession(): (idToken: string, publicKey: string
|
|
|
10
10
|
|
|
11
11
|
declare function useCreateWeb3Account(): (idToken: string, publicKey: string, userPid: string, authServiceBaseUrl: string) => Promise<any>;
|
|
12
12
|
|
|
13
|
-
declare function useFetchUserData(): (dbAuthToken: string, endpoint: string) => Promise<any>;
|
|
13
|
+
declare function useFetchUserData(): (dbAuthToken: string, endpoint: string, walletAddress: string) => Promise<any>;
|
|
14
14
|
|
|
15
15
|
declare function useUpdateUserEmail(): (dbAuthToken: string, docID: string, email: string, endpoint: string) => Promise<void>;
|
|
16
16
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ declare function useVerifyWeb3AuthSession(): (idToken: string, publicKey: string
|
|
|
10
10
|
|
|
11
11
|
declare function useCreateWeb3Account(): (idToken: string, publicKey: string, userPid: string, authServiceBaseUrl: string) => Promise<any>;
|
|
12
12
|
|
|
13
|
-
declare function useFetchUserData(): (dbAuthToken: string, endpoint: string) => Promise<any>;
|
|
13
|
+
declare function useFetchUserData(): (dbAuthToken: string, endpoint: string, walletAddress: string) => Promise<any>;
|
|
14
14
|
|
|
15
15
|
declare function useUpdateUserEmail(): (dbAuthToken: string, docID: string, email: string, endpoint: string) => Promise<void>;
|
|
16
16
|
|
package/dist/index.js
CHANGED
|
@@ -145,45 +145,47 @@ function useCreateWeb3Account() {
|
|
|
145
145
|
// src/utils/account/useFetchUserData.ts
|
|
146
146
|
var import_react4 = require("react");
|
|
147
147
|
function useFetchUserData() {
|
|
148
|
-
return (0, import_react4.useCallback)(
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
return (0, import_react4.useCallback)(
|
|
149
|
+
async (dbAuthToken, endpoint, walletAddress) => {
|
|
150
|
+
try {
|
|
151
|
+
const query = `
|
|
151
152
|
query User {
|
|
152
|
-
User {
|
|
153
|
+
User(filter: { baseWalletAddress: { _eq: ${walletAddress} } }) {
|
|
153
154
|
_docID
|
|
154
155
|
pid
|
|
155
156
|
email
|
|
156
157
|
name
|
|
157
158
|
isVerified
|
|
158
159
|
showTooltips
|
|
159
|
-
accountType
|
|
160
160
|
baseWalletAddress
|
|
161
161
|
stripeCustomerId
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
`;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
165
|
+
const response = await fetch(endpoint, {
|
|
166
|
+
method: "POST",
|
|
167
|
+
headers: {
|
|
168
|
+
"Content-Type": "application/json",
|
|
169
|
+
Authorization: `Bearer ${dbAuthToken}`
|
|
170
|
+
},
|
|
171
|
+
body: JSON.stringify({ query })
|
|
172
|
+
});
|
|
173
|
+
if (!response.ok) {
|
|
174
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
175
|
+
}
|
|
176
|
+
const data = await response.json();
|
|
177
|
+
if (data && data.data && data.data.User && data.data.User.length > 0) {
|
|
178
|
+
return data.data.User[0];
|
|
179
|
+
} else {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error("Error fetching user data:", error);
|
|
180
184
|
return null;
|
|
181
185
|
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
}, []);
|
|
186
|
+
},
|
|
187
|
+
[]
|
|
188
|
+
);
|
|
187
189
|
}
|
|
188
190
|
|
|
189
191
|
// src/utils/account/useUpdateUserEmail.ts
|
package/dist/index.mjs
CHANGED
|
@@ -82,45 +82,47 @@ function useCreateWeb3Account() {
|
|
|
82
82
|
// src/utils/account/useFetchUserData.ts
|
|
83
83
|
import { useCallback as useCallback4 } from "react";
|
|
84
84
|
function useFetchUserData() {
|
|
85
|
-
return useCallback4(
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
return useCallback4(
|
|
86
|
+
async (dbAuthToken, endpoint, walletAddress) => {
|
|
87
|
+
try {
|
|
88
|
+
const query = `
|
|
88
89
|
query User {
|
|
89
|
-
User {
|
|
90
|
+
User(filter: { baseWalletAddress: { _eq: ${walletAddress} } }) {
|
|
90
91
|
_docID
|
|
91
92
|
pid
|
|
92
93
|
email
|
|
93
94
|
name
|
|
94
95
|
isVerified
|
|
95
96
|
showTooltips
|
|
96
|
-
accountType
|
|
97
97
|
baseWalletAddress
|
|
98
98
|
stripeCustomerId
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
`;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
const response = await fetch(endpoint, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: {
|
|
105
|
+
"Content-Type": "application/json",
|
|
106
|
+
Authorization: `Bearer ${dbAuthToken}`
|
|
107
|
+
},
|
|
108
|
+
body: JSON.stringify({ query })
|
|
109
|
+
});
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
112
|
+
}
|
|
113
|
+
const data = await response.json();
|
|
114
|
+
if (data && data.data && data.data.User && data.data.User.length > 0) {
|
|
115
|
+
return data.data.User[0];
|
|
116
|
+
} else {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("Error fetching user data:", error);
|
|
117
121
|
return null;
|
|
118
122
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
}, []);
|
|
123
|
+
},
|
|
124
|
+
[]
|
|
125
|
+
);
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
// src/utils/account/useUpdateUserEmail.ts
|
package/package.json
CHANGED
package/dist/chunk-43I5M7QS.mjs
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-5UXBNDDZ.mjs
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-DIGESQEI.mjs
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-KEC6WLEL.mjs
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-QHK3YPLJ.mjs
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
};
|