anymal-protocol 1.0.57 → 1.0.60
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-F72KTNHS.mjs +98 -0
- package/dist/chunk-KEC6WLEL.mjs +93 -0
- package/dist/chunk-QHK3YPLJ.mjs +93 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +165 -0
- package/dist/cli/index.mjs +101 -0
- package/dist/index.d.mts +78 -1
- package/dist/index.d.ts +78 -1
- package/dist/index.js +176 -19
- package/dist/index.mjs +97 -19
- package/package.json +17 -3
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// src/cli/index.ts
|
|
5
|
+
var import_commander = require("commander");
|
|
6
|
+
|
|
7
|
+
// src/helpers/CryptoUtils.tsx
|
|
8
|
+
var import_elliptic = require("elliptic");
|
|
9
|
+
var ec = new import_elliptic.ec("secp256k1");
|
|
10
|
+
var NETWORK_HOSTS = {
|
|
11
|
+
["testnet" /* Testnet */]: "dev-db.petastic.com",
|
|
12
|
+
["localnet" /* Localnet */]: "host.docker.internal:9181"
|
|
13
|
+
};
|
|
14
|
+
var AUTH_API_ENDPOINTS = {
|
|
15
|
+
["testnet" /* Testnet */]: "https://dev-auth-api.petastic.com",
|
|
16
|
+
["localnet" /* Localnet */]: "http://localhost:3005"
|
|
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
|
+
|
|
75
|
+
// src/helpers/AppHelpers.tsx
|
|
76
|
+
async function createApp(privateKeyHex, name, metadataURI, ownerEmail, network = "testnet" /* Testnet */, options) {
|
|
77
|
+
const { publicKey, token } = await createAuthEnvelope(
|
|
78
|
+
privateKeyHex,
|
|
79
|
+
network,
|
|
80
|
+
options
|
|
81
|
+
);
|
|
82
|
+
const host = AUTH_API_ENDPOINTS[network];
|
|
83
|
+
if (!host) {
|
|
84
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
85
|
+
}
|
|
86
|
+
const url = `${host}/create-app`;
|
|
87
|
+
const response = await fetch(url, {
|
|
88
|
+
method: "POST",
|
|
89
|
+
headers: {
|
|
90
|
+
"Content-Type": "application/json",
|
|
91
|
+
Authorization: `Bearer ${token}`
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
name,
|
|
95
|
+
publicKey,
|
|
96
|
+
metadataURI,
|
|
97
|
+
ownerEmail
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
const text = await response.text();
|
|
102
|
+
throw new Error(`Error creating app (${response.status}): ${text}`);
|
|
103
|
+
}
|
|
104
|
+
return response.json();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/cli/index.ts
|
|
108
|
+
var program = new import_commander.Command();
|
|
109
|
+
program.name("anymal").description("Anymal Protocol helper CLI").version("1.0.0");
|
|
110
|
+
program.command("keygen").description("Generate a new secp256k1 private key (hex)").action(() => {
|
|
111
|
+
const { ec: EC2 } = require("elliptic");
|
|
112
|
+
const ec2 = new EC2("secp256k1");
|
|
113
|
+
const keyPair = ec2.genKeyPair();
|
|
114
|
+
const privateKeyHex = keyPair.getPrivate("hex");
|
|
115
|
+
console.log(privateKeyHex);
|
|
116
|
+
});
|
|
117
|
+
program.command("auth").description("Print publicKey and JWT for your APP_PRIV_HEX").option("-n, --network <net>", "network to target", "testnet").action(async (opts) => {
|
|
118
|
+
const hex = process.env.APP_PRIV_HEX;
|
|
119
|
+
if (!hex) {
|
|
120
|
+
console.error("\u274C Set APP_PRIV_HEX first");
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
let net;
|
|
124
|
+
switch (opts.network.toLowerCase()) {
|
|
125
|
+
case "localnet":
|
|
126
|
+
net = "localnet" /* Localnet */;
|
|
127
|
+
break;
|
|
128
|
+
case "testnet":
|
|
129
|
+
net = "testnet" /* Testnet */;
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
console.error(`\u274C Unsupported network: ${opts.network}`);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
const { publicKey, token } = await createAuthEnvelope(hex, net);
|
|
136
|
+
console.log("publicKey:", publicKey);
|
|
137
|
+
console.log("token:", token);
|
|
138
|
+
});
|
|
139
|
+
program.command("create-app").description("Register a new application on-chain").requiredOption("--name <name>", "application name").requiredOption("--email <ownerEmail>", "owner email").option("--metadata <uri>", "metadata URI", "").option("-n, --network <net>", "network", "testnet").action(async (opts) => {
|
|
140
|
+
const hex = process.env.APP_PRIV_HEX;
|
|
141
|
+
if (!hex) {
|
|
142
|
+
console.error("\u274C Set APP_PRIV_HEX first");
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
let net;
|
|
146
|
+
switch (opts.network.toLowerCase()) {
|
|
147
|
+
case "localnet":
|
|
148
|
+
net = "localnet" /* Localnet */;
|
|
149
|
+
break;
|
|
150
|
+
case "testnet":
|
|
151
|
+
net = "testnet" /* Testnet */;
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
console.error(`\u274C Unsupported network: ${opts.network}`);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const res = await createApp(hex, opts.name, opts.metadata, opts.email, net);
|
|
159
|
+
console.log(JSON.stringify(res, null, 2));
|
|
160
|
+
} catch (e) {
|
|
161
|
+
console.error("\u274C create-app failed:", e.message);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
program.parse();
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
AUTH_API_ENDPOINTS,
|
|
4
|
+
__require,
|
|
5
|
+
createAuthEnvelope
|
|
6
|
+
} from "../chunk-F72KTNHS.mjs";
|
|
7
|
+
|
|
8
|
+
// src/cli/index.ts
|
|
9
|
+
import { Command } from "commander";
|
|
10
|
+
|
|
11
|
+
// src/helpers/AppHelpers.tsx
|
|
12
|
+
async function createApp(privateKeyHex, name, metadataURI, ownerEmail, network = "testnet" /* Testnet */, options) {
|
|
13
|
+
const { publicKey, token } = await createAuthEnvelope(
|
|
14
|
+
privateKeyHex,
|
|
15
|
+
network,
|
|
16
|
+
options
|
|
17
|
+
);
|
|
18
|
+
const host = AUTH_API_ENDPOINTS[network];
|
|
19
|
+
if (!host) {
|
|
20
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
21
|
+
}
|
|
22
|
+
const url = `${host}/create-app`;
|
|
23
|
+
const response = await fetch(url, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
Authorization: `Bearer ${token}`
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify({
|
|
30
|
+
name,
|
|
31
|
+
publicKey,
|
|
32
|
+
metadataURI,
|
|
33
|
+
ownerEmail
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const text = await response.text();
|
|
38
|
+
throw new Error(`Error creating app (${response.status}): ${text}`);
|
|
39
|
+
}
|
|
40
|
+
return response.json();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/cli/index.ts
|
|
44
|
+
var program = new Command();
|
|
45
|
+
program.name("anymal").description("Anymal Protocol helper CLI").version("1.0.0");
|
|
46
|
+
program.command("keygen").description("Generate a new secp256k1 private key (hex)").action(() => {
|
|
47
|
+
const { ec: EC } = __require("elliptic");
|
|
48
|
+
const ec = new EC("secp256k1");
|
|
49
|
+
const keyPair = ec.genKeyPair();
|
|
50
|
+
const privateKeyHex = keyPair.getPrivate("hex");
|
|
51
|
+
console.log(privateKeyHex);
|
|
52
|
+
});
|
|
53
|
+
program.command("auth").description("Print publicKey and JWT for your APP_PRIV_HEX").option("-n, --network <net>", "network to target", "testnet").action(async (opts) => {
|
|
54
|
+
const hex = process.env.APP_PRIV_HEX;
|
|
55
|
+
if (!hex) {
|
|
56
|
+
console.error("\u274C Set APP_PRIV_HEX first");
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
let net;
|
|
60
|
+
switch (opts.network.toLowerCase()) {
|
|
61
|
+
case "localnet":
|
|
62
|
+
net = "localnet" /* Localnet */;
|
|
63
|
+
break;
|
|
64
|
+
case "testnet":
|
|
65
|
+
net = "testnet" /* Testnet */;
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
console.error(`\u274C Unsupported network: ${opts.network}`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
const { publicKey, token } = await createAuthEnvelope(hex, net);
|
|
72
|
+
console.log("publicKey:", publicKey);
|
|
73
|
+
console.log("token:", token);
|
|
74
|
+
});
|
|
75
|
+
program.command("create-app").description("Register a new application on-chain").requiredOption("--name <name>", "application name").requiredOption("--email <ownerEmail>", "owner email").option("--metadata <uri>", "metadata URI", "").option("-n, --network <net>", "network", "testnet").action(async (opts) => {
|
|
76
|
+
const hex = process.env.APP_PRIV_HEX;
|
|
77
|
+
if (!hex) {
|
|
78
|
+
console.error("\u274C Set APP_PRIV_HEX first");
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
let net;
|
|
82
|
+
switch (opts.network.toLowerCase()) {
|
|
83
|
+
case "localnet":
|
|
84
|
+
net = "localnet" /* Localnet */;
|
|
85
|
+
break;
|
|
86
|
+
case "testnet":
|
|
87
|
+
net = "testnet" /* Testnet */;
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
console.error(`\u274C Unsupported network: ${opts.network}`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const res = await createApp(hex, opts.name, opts.metadata, opts.email, net);
|
|
95
|
+
console.log(JSON.stringify(res, null, 2));
|
|
96
|
+
} catch (e) {
|
|
97
|
+
console.error("\u274C create-app failed:", e.message);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
program.parse();
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BundlerClient } from 'viem/account-abstraction';
|
|
2
|
+
import { ec } from 'elliptic';
|
|
2
3
|
|
|
3
4
|
declare function useVerifyAccount(): (pid: string, campaignId: string, dbAuthToken: string, bundlerClient: any, smartAccount: any, accountRewardsContractAddress: `0x${string}`) => Promise<{
|
|
4
5
|
success: boolean;
|
|
@@ -82,6 +83,14 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
|
|
|
82
83
|
type: string;
|
|
83
84
|
}>;
|
|
84
85
|
|
|
86
|
+
declare function fetchAnymals({ dbAuthToken, endpoint, userPid, }: {
|
|
87
|
+
dbAuthToken: string;
|
|
88
|
+
endpoint: string;
|
|
89
|
+
userPid: string;
|
|
90
|
+
}): Promise<any>;
|
|
91
|
+
|
|
92
|
+
declare function useFetchAnymals(): typeof fetchAnymals;
|
|
93
|
+
|
|
85
94
|
declare function useProcessPartialKibblePayment(): (pid: string, nftId: string, orderId: string, dbAuthToken: string, marketplaceContract: string, smartAccount: any, bundlerClient: any, amountInTokens: string, maxTokenPayment: string, nonce: string, deadline: string, backendSignature: string) => Promise<{
|
|
86
95
|
success: boolean;
|
|
87
96
|
message: string;
|
|
@@ -137,6 +146,74 @@ declare function useUpdateOrgWalletAddress(): (dbAuthToken: string, docID: strin
|
|
|
137
146
|
|
|
138
147
|
declare const generateBytes32Nonce: () => `0x${string}`;
|
|
139
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Supported networks
|
|
151
|
+
*/
|
|
152
|
+
declare enum Network {
|
|
153
|
+
Testnet = "testnet",
|
|
154
|
+
Localnet = "localnet"
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Mapping from network to audience host
|
|
158
|
+
*/
|
|
159
|
+
declare const NETWORK_HOSTS: Record<Network, string>;
|
|
160
|
+
/**
|
|
161
|
+
* Mapping from network to audience host
|
|
162
|
+
*/
|
|
163
|
+
declare const AUTH_API_ENDPOINTS: Record<Network, string>;
|
|
164
|
+
/**
|
|
165
|
+
* Output of authentication envelope
|
|
166
|
+
*/
|
|
167
|
+
interface AuthEnvelope {
|
|
168
|
+
publicKey: string;
|
|
169
|
+
token: string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Options when creating JWT
|
|
173
|
+
*/
|
|
174
|
+
interface JWTOptions {
|
|
175
|
+
/**
|
|
176
|
+
* Time-to-live in seconds (default: 24h)
|
|
177
|
+
*/
|
|
178
|
+
expiresInSeconds?: number;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Load a secp256k1 private key from a hex string.
|
|
182
|
+
* @param hexKey - Hex‑encoded private key
|
|
183
|
+
*/
|
|
184
|
+
declare function loadExistingSecp256k1PrivateKey(hexKey: string): ec.KeyPair;
|
|
185
|
+
/**
|
|
186
|
+
* Serialize the public key (compressed 02/03 + X) to hex.
|
|
187
|
+
* @param keyPair - The elliptic KeyPair
|
|
188
|
+
*/
|
|
189
|
+
declare function serializePublicKeyCompressed(keyPair: ec.KeyPair): string;
|
|
190
|
+
/**
|
|
191
|
+
* Generate a JWT signed with ES256 (ECDSA + SHA-256) directly from a secp256k1 key pair.
|
|
192
|
+
* Using `ES256` header so it matches PyJWT verification.
|
|
193
|
+
* @param sub - Subject claim (e.g., compressed public key)
|
|
194
|
+
* @param aud - Audience claim (e.g., host/domain)
|
|
195
|
+
* @param keyPair - Elliptic KeyPair for signing
|
|
196
|
+
* @param expiresInSeconds - TTL in seconds (default: 24h)
|
|
197
|
+
*/
|
|
198
|
+
declare function generateJWT(sub: string, aud: string, keyPair: ec.KeyPair, expiresInSeconds?: number): Promise<string>;
|
|
199
|
+
/**
|
|
200
|
+
* Convenience wrapper: given a hex private key and host/domain,
|
|
201
|
+
* returns a compressed public key and a JWT signed with that key.
|
|
202
|
+
* @param privateKeyHex - Hex‑encoded secp256k1 private key
|
|
203
|
+
* @param network - testnet/mainnet network identifier
|
|
204
|
+
* @param options - Optional settings like expiresInSeconds
|
|
205
|
+
*/
|
|
206
|
+
declare function createAuthEnvelope(privateKeyHex: string, network?: Network, options?: JWTOptions): Promise<AuthEnvelope>;
|
|
207
|
+
/**
|
|
208
|
+
* Generate a hex‑encoded DER signature for the OAuth‑style
|
|
209
|
+
* verify‑app‑session call.
|
|
210
|
+
* @param privateKeyHex - Hex‑encoded secp256k1 private key
|
|
211
|
+
* @param clientId - Your app’s App ID
|
|
212
|
+
* @param redirectUri - Redirect URI used in the OAuth flow
|
|
213
|
+
* @param state - CSRF/state parameter used in the flow
|
|
214
|
+
*/
|
|
215
|
+
declare function generateAppSignature(privateKeyHex: string, clientId: string, redirectUri: string, state: string): Promise<string>;
|
|
216
|
+
|
|
140
217
|
declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<{
|
|
141
218
|
success: boolean;
|
|
142
219
|
data: any;
|
|
@@ -149,4 +226,4 @@ declare function useCreateOrganizationAppData(): (appId: string, pid: string, db
|
|
|
149
226
|
|
|
150
227
|
declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
|
|
151
228
|
|
|
152
|
-
export { type AnymalNftMetadataInputData, type CreateAnymalInputData, generateBytes32Nonce, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
|
|
229
|
+
export { AUTH_API_ENDPOINTS, type AnymalNftMetadataInputData, type AuthEnvelope, type CreateAnymalInputData, type JWTOptions, NETWORK_HOSTS, Network, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BundlerClient } from 'viem/account-abstraction';
|
|
2
|
+
import { ec } from 'elliptic';
|
|
2
3
|
|
|
3
4
|
declare function useVerifyAccount(): (pid: string, campaignId: string, dbAuthToken: string, bundlerClient: any, smartAccount: any, accountRewardsContractAddress: `0x${string}`) => Promise<{
|
|
4
5
|
success: boolean;
|
|
@@ -82,6 +83,14 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
|
|
|
82
83
|
type: string;
|
|
83
84
|
}>;
|
|
84
85
|
|
|
86
|
+
declare function fetchAnymals({ dbAuthToken, endpoint, userPid, }: {
|
|
87
|
+
dbAuthToken: string;
|
|
88
|
+
endpoint: string;
|
|
89
|
+
userPid: string;
|
|
90
|
+
}): Promise<any>;
|
|
91
|
+
|
|
92
|
+
declare function useFetchAnymals(): typeof fetchAnymals;
|
|
93
|
+
|
|
85
94
|
declare function useProcessPartialKibblePayment(): (pid: string, nftId: string, orderId: string, dbAuthToken: string, marketplaceContract: string, smartAccount: any, bundlerClient: any, amountInTokens: string, maxTokenPayment: string, nonce: string, deadline: string, backendSignature: string) => Promise<{
|
|
86
95
|
success: boolean;
|
|
87
96
|
message: string;
|
|
@@ -137,6 +146,74 @@ declare function useUpdateOrgWalletAddress(): (dbAuthToken: string, docID: strin
|
|
|
137
146
|
|
|
138
147
|
declare const generateBytes32Nonce: () => `0x${string}`;
|
|
139
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Supported networks
|
|
151
|
+
*/
|
|
152
|
+
declare enum Network {
|
|
153
|
+
Testnet = "testnet",
|
|
154
|
+
Localnet = "localnet"
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Mapping from network to audience host
|
|
158
|
+
*/
|
|
159
|
+
declare const NETWORK_HOSTS: Record<Network, string>;
|
|
160
|
+
/**
|
|
161
|
+
* Mapping from network to audience host
|
|
162
|
+
*/
|
|
163
|
+
declare const AUTH_API_ENDPOINTS: Record<Network, string>;
|
|
164
|
+
/**
|
|
165
|
+
* Output of authentication envelope
|
|
166
|
+
*/
|
|
167
|
+
interface AuthEnvelope {
|
|
168
|
+
publicKey: string;
|
|
169
|
+
token: string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Options when creating JWT
|
|
173
|
+
*/
|
|
174
|
+
interface JWTOptions {
|
|
175
|
+
/**
|
|
176
|
+
* Time-to-live in seconds (default: 24h)
|
|
177
|
+
*/
|
|
178
|
+
expiresInSeconds?: number;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Load a secp256k1 private key from a hex string.
|
|
182
|
+
* @param hexKey - Hex‑encoded private key
|
|
183
|
+
*/
|
|
184
|
+
declare function loadExistingSecp256k1PrivateKey(hexKey: string): ec.KeyPair;
|
|
185
|
+
/**
|
|
186
|
+
* Serialize the public key (compressed 02/03 + X) to hex.
|
|
187
|
+
* @param keyPair - The elliptic KeyPair
|
|
188
|
+
*/
|
|
189
|
+
declare function serializePublicKeyCompressed(keyPair: ec.KeyPair): string;
|
|
190
|
+
/**
|
|
191
|
+
* Generate a JWT signed with ES256 (ECDSA + SHA-256) directly from a secp256k1 key pair.
|
|
192
|
+
* Using `ES256` header so it matches PyJWT verification.
|
|
193
|
+
* @param sub - Subject claim (e.g., compressed public key)
|
|
194
|
+
* @param aud - Audience claim (e.g., host/domain)
|
|
195
|
+
* @param keyPair - Elliptic KeyPair for signing
|
|
196
|
+
* @param expiresInSeconds - TTL in seconds (default: 24h)
|
|
197
|
+
*/
|
|
198
|
+
declare function generateJWT(sub: string, aud: string, keyPair: ec.KeyPair, expiresInSeconds?: number): Promise<string>;
|
|
199
|
+
/**
|
|
200
|
+
* Convenience wrapper: given a hex private key and host/domain,
|
|
201
|
+
* returns a compressed public key and a JWT signed with that key.
|
|
202
|
+
* @param privateKeyHex - Hex‑encoded secp256k1 private key
|
|
203
|
+
* @param network - testnet/mainnet network identifier
|
|
204
|
+
* @param options - Optional settings like expiresInSeconds
|
|
205
|
+
*/
|
|
206
|
+
declare function createAuthEnvelope(privateKeyHex: string, network?: Network, options?: JWTOptions): Promise<AuthEnvelope>;
|
|
207
|
+
/**
|
|
208
|
+
* Generate a hex‑encoded DER signature for the OAuth‑style
|
|
209
|
+
* verify‑app‑session call.
|
|
210
|
+
* @param privateKeyHex - Hex‑encoded secp256k1 private key
|
|
211
|
+
* @param clientId - Your app’s App ID
|
|
212
|
+
* @param redirectUri - Redirect URI used in the OAuth flow
|
|
213
|
+
* @param state - CSRF/state parameter used in the flow
|
|
214
|
+
*/
|
|
215
|
+
declare function generateAppSignature(privateKeyHex: string, clientId: string, redirectUri: string, state: string): Promise<string>;
|
|
216
|
+
|
|
140
217
|
declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<{
|
|
141
218
|
success: boolean;
|
|
142
219
|
data: any;
|
|
@@ -149,4 +226,4 @@ declare function useCreateOrganizationAppData(): (appId: string, pid: string, db
|
|
|
149
226
|
|
|
150
227
|
declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
|
|
151
228
|
|
|
152
|
-
export { type AnymalNftMetadataInputData, type CreateAnymalInputData, generateBytes32Nonce, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
|
|
229
|
+
export { AUTH_API_ENDPOINTS, type AnymalNftMetadataInputData, type AuthEnvelope, type CreateAnymalInputData, type JWTOptions, NETWORK_HOSTS, Network, createAuthEnvelope, fetchAnymals, generateAppSignature, generateBytes32Nonce, generateJWT, loadExistingSecp256k1PrivateKey, serializePublicKeyCompressed, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
|