anymal-protocol 1.0.59 → 1.0.61
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 +174 -1
- package/dist/index.d.ts +174 -1
- package/dist/index.js +244 -19
- package/dist/index.mjs +162 -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;
|
|
@@ -60,6 +61,7 @@ interface AnymalNftMetadataInputData {
|
|
|
60
61
|
|
|
61
62
|
declare function useAddAnymalToDatabase(): (dbAuthToken: string, endpoint: string, anymalData: CreateAnymalInputData) => Promise<{
|
|
62
63
|
_docID: string | null;
|
|
64
|
+
dbCid: string | null;
|
|
63
65
|
success: boolean;
|
|
64
66
|
message: string;
|
|
65
67
|
}>;
|
|
@@ -82,6 +84,14 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
|
|
|
82
84
|
type: string;
|
|
83
85
|
}>;
|
|
84
86
|
|
|
87
|
+
declare function fetchAnymals({ dbAuthToken, endpoint, userPid, }: {
|
|
88
|
+
dbAuthToken: string;
|
|
89
|
+
endpoint: string;
|
|
90
|
+
userPid: string;
|
|
91
|
+
}): Promise<any>;
|
|
92
|
+
|
|
93
|
+
declare function useFetchAnymals(): typeof fetchAnymals;
|
|
94
|
+
|
|
85
95
|
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
96
|
success: boolean;
|
|
87
97
|
message: string;
|
|
@@ -137,6 +147,169 @@ declare function useUpdateOrgWalletAddress(): (dbAuthToken: string, docID: strin
|
|
|
137
147
|
|
|
138
148
|
declare const generateBytes32Nonce: () => `0x${string}`;
|
|
139
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Supported networks
|
|
152
|
+
*/
|
|
153
|
+
declare enum Network {
|
|
154
|
+
Testnet = "testnet",
|
|
155
|
+
Localnet = "localnet"
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Mapping from network to audience host
|
|
159
|
+
*/
|
|
160
|
+
declare const NETWORK_HOSTS: Record<Network, string>;
|
|
161
|
+
/**
|
|
162
|
+
* Mapping from network to audience host
|
|
163
|
+
*/
|
|
164
|
+
declare const AUTH_API_ENDPOINTS: Record<Network, string>;
|
|
165
|
+
/**
|
|
166
|
+
* Output of authentication envelope
|
|
167
|
+
*/
|
|
168
|
+
interface AuthEnvelope {
|
|
169
|
+
publicKey: string;
|
|
170
|
+
token: string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Options when creating JWT
|
|
174
|
+
*/
|
|
175
|
+
interface JWTOptions {
|
|
176
|
+
/**
|
|
177
|
+
* Time-to-live in seconds (default: 24h)
|
|
178
|
+
*/
|
|
179
|
+
expiresInSeconds?: number;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Load a secp256k1 private key from a hex string.
|
|
183
|
+
* @param hexKey - Hex‑encoded private key
|
|
184
|
+
*/
|
|
185
|
+
declare function loadExistingSecp256k1PrivateKey(hexKey: string): ec.KeyPair;
|
|
186
|
+
/**
|
|
187
|
+
* Serialize the public key (compressed 02/03 + X) to hex.
|
|
188
|
+
* @param keyPair - The elliptic KeyPair
|
|
189
|
+
*/
|
|
190
|
+
declare function serializePublicKeyCompressed(keyPair: ec.KeyPair): string;
|
|
191
|
+
/**
|
|
192
|
+
* Generate a JWT signed with ES256 (ECDSA + SHA-256) directly from a secp256k1 key pair.
|
|
193
|
+
* Using `ES256` header so it matches PyJWT verification.
|
|
194
|
+
* @param sub - Subject claim (e.g., compressed public key)
|
|
195
|
+
* @param aud - Audience claim (e.g., host/domain)
|
|
196
|
+
* @param keyPair - Elliptic KeyPair for signing
|
|
197
|
+
* @param expiresInSeconds - TTL in seconds (default: 24h)
|
|
198
|
+
*/
|
|
199
|
+
declare function generateJWT(sub: string, aud: string, keyPair: ec.KeyPair, expiresInSeconds?: number): Promise<string>;
|
|
200
|
+
/**
|
|
201
|
+
* Convenience wrapper: given a hex private key and host/domain,
|
|
202
|
+
* returns a compressed public key and a JWT signed with that key.
|
|
203
|
+
* @param privateKeyHex - Hex‑encoded secp256k1 private key
|
|
204
|
+
* @param network - testnet/mainnet network identifier
|
|
205
|
+
* @param options - Optional settings like expiresInSeconds
|
|
206
|
+
*/
|
|
207
|
+
declare function createAuthEnvelope(privateKeyHex: string, network?: Network, options?: JWTOptions): Promise<AuthEnvelope>;
|
|
208
|
+
/**
|
|
209
|
+
* Generate a hex‑encoded DER signature for the OAuth‑style
|
|
210
|
+
* verify‑app‑session call.
|
|
211
|
+
* @param privateKeyHex - Hex‑encoded secp256k1 private key
|
|
212
|
+
* @param clientId - Your app’s App ID
|
|
213
|
+
* @param redirectUri - Redirect URI used in the OAuth flow
|
|
214
|
+
* @param state - CSRF/state parameter used in the flow
|
|
215
|
+
*/
|
|
216
|
+
declare function generateAppSignature(privateKeyHex: string, clientId: string, redirectUri: string, state: string): Promise<string>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Types of actions you can submit
|
|
220
|
+
*/
|
|
221
|
+
declare enum ActionType {
|
|
222
|
+
GRAPHQL = "GRAPHQL",
|
|
223
|
+
CONTRACT = "CONTRACT",
|
|
224
|
+
EXTERNAL = "EXTERNAL"
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Represents a single action record returned by the backend.
|
|
228
|
+
*/
|
|
229
|
+
interface ActionRecord {
|
|
230
|
+
id: string;
|
|
231
|
+
wallet: string;
|
|
232
|
+
pid: string;
|
|
233
|
+
action_id: string;
|
|
234
|
+
metadata: Record<string, any>;
|
|
235
|
+
version_cid?: string;
|
|
236
|
+
quantity: number;
|
|
237
|
+
reward_amount?: number;
|
|
238
|
+
status: 'PENDING' | 'VALIDATED' | 'CLAIMED';
|
|
239
|
+
createdAt: string;
|
|
240
|
+
validatedAt?: string | null;
|
|
241
|
+
claimedAt?: string | null;
|
|
242
|
+
claimQuantity?: number | null;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* API response for fetching action records.
|
|
246
|
+
*/
|
|
247
|
+
interface FetchActionsResponse {
|
|
248
|
+
data: ActionRecord[];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Base fields sent with every action
|
|
253
|
+
*/
|
|
254
|
+
interface BaseActionPayload {
|
|
255
|
+
actionId: string;
|
|
256
|
+
timestamp: string;
|
|
257
|
+
nonce: string;
|
|
258
|
+
source: ActionType;
|
|
259
|
+
clientInfo?: {
|
|
260
|
+
userAgent?: string;
|
|
261
|
+
locale?: string;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Payload for GraphQL-based actions
|
|
266
|
+
*/
|
|
267
|
+
interface GraphQLActionPayload extends BaseActionPayload {
|
|
268
|
+
versionCid: string;
|
|
269
|
+
resource: string;
|
|
270
|
+
resourceId: string;
|
|
271
|
+
changedFields?: string[];
|
|
272
|
+
previousValues?: Record<string, any>;
|
|
273
|
+
mutation?: string;
|
|
274
|
+
variables?: Record<string, any>;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Payload for on-chain contract actions
|
|
278
|
+
*/
|
|
279
|
+
interface ContractActionPayload extends BaseActionPayload {
|
|
280
|
+
txHash: string;
|
|
281
|
+
chainId: number;
|
|
282
|
+
contract: string;
|
|
283
|
+
functionName: string;
|
|
284
|
+
args: any[];
|
|
285
|
+
receipt: {
|
|
286
|
+
blockNumber: number;
|
|
287
|
+
status: number;
|
|
288
|
+
gasUsed: string;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Payload for external web-service actions
|
|
293
|
+
*/
|
|
294
|
+
interface ExternalActionPayload extends BaseActionPayload {
|
|
295
|
+
endpoint: string;
|
|
296
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
297
|
+
requestBody?: Record<string, any>;
|
|
298
|
+
responseStatus?: number;
|
|
299
|
+
responseBody?: any;
|
|
300
|
+
}
|
|
301
|
+
type ActionPayload = GraphQLActionPayload | ContractActionPayload | ExternalActionPayload;
|
|
302
|
+
interface SubmitResponse {
|
|
303
|
+
ok: boolean;
|
|
304
|
+
id: string;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Generic submission function
|
|
308
|
+
*/
|
|
309
|
+
declare function submitAction(idToken: string, pid: string, payload: ActionPayload, endpointBaseUrl: string): Promise<SubmitResponse>;
|
|
310
|
+
|
|
311
|
+
declare function useFetchActions(): (idToken: string, actionsServiceBaseUrl: string, pid: string, status?: string, limit?: number, offset?: number) => Promise<FetchActionsResponse | null>;
|
|
312
|
+
|
|
140
313
|
declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<{
|
|
141
314
|
success: boolean;
|
|
142
315
|
data: any;
|
|
@@ -149,4 +322,4 @@ declare function useCreateOrganizationAppData(): (appId: string, pid: string, db
|
|
|
149
322
|
|
|
150
323
|
declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
|
|
151
324
|
|
|
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 };
|
|
325
|
+
export { AUTH_API_ENDPOINTS, type ActionPayload, 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, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActions, 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;
|
|
@@ -60,6 +61,7 @@ interface AnymalNftMetadataInputData {
|
|
|
60
61
|
|
|
61
62
|
declare function useAddAnymalToDatabase(): (dbAuthToken: string, endpoint: string, anymalData: CreateAnymalInputData) => Promise<{
|
|
62
63
|
_docID: string | null;
|
|
64
|
+
dbCid: string | null;
|
|
63
65
|
success: boolean;
|
|
64
66
|
message: string;
|
|
65
67
|
}>;
|
|
@@ -82,6 +84,14 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
|
|
|
82
84
|
type: string;
|
|
83
85
|
}>;
|
|
84
86
|
|
|
87
|
+
declare function fetchAnymals({ dbAuthToken, endpoint, userPid, }: {
|
|
88
|
+
dbAuthToken: string;
|
|
89
|
+
endpoint: string;
|
|
90
|
+
userPid: string;
|
|
91
|
+
}): Promise<any>;
|
|
92
|
+
|
|
93
|
+
declare function useFetchAnymals(): typeof fetchAnymals;
|
|
94
|
+
|
|
85
95
|
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
96
|
success: boolean;
|
|
87
97
|
message: string;
|
|
@@ -137,6 +147,169 @@ declare function useUpdateOrgWalletAddress(): (dbAuthToken: string, docID: strin
|
|
|
137
147
|
|
|
138
148
|
declare const generateBytes32Nonce: () => `0x${string}`;
|
|
139
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Supported networks
|
|
152
|
+
*/
|
|
153
|
+
declare enum Network {
|
|
154
|
+
Testnet = "testnet",
|
|
155
|
+
Localnet = "localnet"
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Mapping from network to audience host
|
|
159
|
+
*/
|
|
160
|
+
declare const NETWORK_HOSTS: Record<Network, string>;
|
|
161
|
+
/**
|
|
162
|
+
* Mapping from network to audience host
|
|
163
|
+
*/
|
|
164
|
+
declare const AUTH_API_ENDPOINTS: Record<Network, string>;
|
|
165
|
+
/**
|
|
166
|
+
* Output of authentication envelope
|
|
167
|
+
*/
|
|
168
|
+
interface AuthEnvelope {
|
|
169
|
+
publicKey: string;
|
|
170
|
+
token: string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Options when creating JWT
|
|
174
|
+
*/
|
|
175
|
+
interface JWTOptions {
|
|
176
|
+
/**
|
|
177
|
+
* Time-to-live in seconds (default: 24h)
|
|
178
|
+
*/
|
|
179
|
+
expiresInSeconds?: number;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Load a secp256k1 private key from a hex string.
|
|
183
|
+
* @param hexKey - Hex‑encoded private key
|
|
184
|
+
*/
|
|
185
|
+
declare function loadExistingSecp256k1PrivateKey(hexKey: string): ec.KeyPair;
|
|
186
|
+
/**
|
|
187
|
+
* Serialize the public key (compressed 02/03 + X) to hex.
|
|
188
|
+
* @param keyPair - The elliptic KeyPair
|
|
189
|
+
*/
|
|
190
|
+
declare function serializePublicKeyCompressed(keyPair: ec.KeyPair): string;
|
|
191
|
+
/**
|
|
192
|
+
* Generate a JWT signed with ES256 (ECDSA + SHA-256) directly from a secp256k1 key pair.
|
|
193
|
+
* Using `ES256` header so it matches PyJWT verification.
|
|
194
|
+
* @param sub - Subject claim (e.g., compressed public key)
|
|
195
|
+
* @param aud - Audience claim (e.g., host/domain)
|
|
196
|
+
* @param keyPair - Elliptic KeyPair for signing
|
|
197
|
+
* @param expiresInSeconds - TTL in seconds (default: 24h)
|
|
198
|
+
*/
|
|
199
|
+
declare function generateJWT(sub: string, aud: string, keyPair: ec.KeyPair, expiresInSeconds?: number): Promise<string>;
|
|
200
|
+
/**
|
|
201
|
+
* Convenience wrapper: given a hex private key and host/domain,
|
|
202
|
+
* returns a compressed public key and a JWT signed with that key.
|
|
203
|
+
* @param privateKeyHex - Hex‑encoded secp256k1 private key
|
|
204
|
+
* @param network - testnet/mainnet network identifier
|
|
205
|
+
* @param options - Optional settings like expiresInSeconds
|
|
206
|
+
*/
|
|
207
|
+
declare function createAuthEnvelope(privateKeyHex: string, network?: Network, options?: JWTOptions): Promise<AuthEnvelope>;
|
|
208
|
+
/**
|
|
209
|
+
* Generate a hex‑encoded DER signature for the OAuth‑style
|
|
210
|
+
* verify‑app‑session call.
|
|
211
|
+
* @param privateKeyHex - Hex‑encoded secp256k1 private key
|
|
212
|
+
* @param clientId - Your app’s App ID
|
|
213
|
+
* @param redirectUri - Redirect URI used in the OAuth flow
|
|
214
|
+
* @param state - CSRF/state parameter used in the flow
|
|
215
|
+
*/
|
|
216
|
+
declare function generateAppSignature(privateKeyHex: string, clientId: string, redirectUri: string, state: string): Promise<string>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Types of actions you can submit
|
|
220
|
+
*/
|
|
221
|
+
declare enum ActionType {
|
|
222
|
+
GRAPHQL = "GRAPHQL",
|
|
223
|
+
CONTRACT = "CONTRACT",
|
|
224
|
+
EXTERNAL = "EXTERNAL"
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Represents a single action record returned by the backend.
|
|
228
|
+
*/
|
|
229
|
+
interface ActionRecord {
|
|
230
|
+
id: string;
|
|
231
|
+
wallet: string;
|
|
232
|
+
pid: string;
|
|
233
|
+
action_id: string;
|
|
234
|
+
metadata: Record<string, any>;
|
|
235
|
+
version_cid?: string;
|
|
236
|
+
quantity: number;
|
|
237
|
+
reward_amount?: number;
|
|
238
|
+
status: 'PENDING' | 'VALIDATED' | 'CLAIMED';
|
|
239
|
+
createdAt: string;
|
|
240
|
+
validatedAt?: string | null;
|
|
241
|
+
claimedAt?: string | null;
|
|
242
|
+
claimQuantity?: number | null;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* API response for fetching action records.
|
|
246
|
+
*/
|
|
247
|
+
interface FetchActionsResponse {
|
|
248
|
+
data: ActionRecord[];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Base fields sent with every action
|
|
253
|
+
*/
|
|
254
|
+
interface BaseActionPayload {
|
|
255
|
+
actionId: string;
|
|
256
|
+
timestamp: string;
|
|
257
|
+
nonce: string;
|
|
258
|
+
source: ActionType;
|
|
259
|
+
clientInfo?: {
|
|
260
|
+
userAgent?: string;
|
|
261
|
+
locale?: string;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Payload for GraphQL-based actions
|
|
266
|
+
*/
|
|
267
|
+
interface GraphQLActionPayload extends BaseActionPayload {
|
|
268
|
+
versionCid: string;
|
|
269
|
+
resource: string;
|
|
270
|
+
resourceId: string;
|
|
271
|
+
changedFields?: string[];
|
|
272
|
+
previousValues?: Record<string, any>;
|
|
273
|
+
mutation?: string;
|
|
274
|
+
variables?: Record<string, any>;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Payload for on-chain contract actions
|
|
278
|
+
*/
|
|
279
|
+
interface ContractActionPayload extends BaseActionPayload {
|
|
280
|
+
txHash: string;
|
|
281
|
+
chainId: number;
|
|
282
|
+
contract: string;
|
|
283
|
+
functionName: string;
|
|
284
|
+
args: any[];
|
|
285
|
+
receipt: {
|
|
286
|
+
blockNumber: number;
|
|
287
|
+
status: number;
|
|
288
|
+
gasUsed: string;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Payload for external web-service actions
|
|
293
|
+
*/
|
|
294
|
+
interface ExternalActionPayload extends BaseActionPayload {
|
|
295
|
+
endpoint: string;
|
|
296
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
297
|
+
requestBody?: Record<string, any>;
|
|
298
|
+
responseStatus?: number;
|
|
299
|
+
responseBody?: any;
|
|
300
|
+
}
|
|
301
|
+
type ActionPayload = GraphQLActionPayload | ContractActionPayload | ExternalActionPayload;
|
|
302
|
+
interface SubmitResponse {
|
|
303
|
+
ok: boolean;
|
|
304
|
+
id: string;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Generic submission function
|
|
308
|
+
*/
|
|
309
|
+
declare function submitAction(idToken: string, pid: string, payload: ActionPayload, endpointBaseUrl: string): Promise<SubmitResponse>;
|
|
310
|
+
|
|
311
|
+
declare function useFetchActions(): (idToken: string, actionsServiceBaseUrl: string, pid: string, status?: string, limit?: number, offset?: number) => Promise<FetchActionsResponse | null>;
|
|
312
|
+
|
|
140
313
|
declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<{
|
|
141
314
|
success: boolean;
|
|
142
315
|
data: any;
|
|
@@ -149,4 +322,4 @@ declare function useCreateOrganizationAppData(): (appId: string, pid: string, db
|
|
|
149
322
|
|
|
150
323
|
declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
|
|
151
324
|
|
|
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 };
|
|
325
|
+
export { AUTH_API_ENDPOINTS, type ActionPayload, 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, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
|