anymal-protocol 1.0.122 → 1.0.124

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.
@@ -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
@@ -1,3 +1,6 @@
1
+ import * as _coinbase_cdp_hooks from '@coinbase/cdp-hooks';
2
+ import * as _coinbase_cdp_api_client from '@coinbase/cdp-api-client';
3
+ import * as abitype from 'abitype';
1
4
  import { BundlerClient } from 'viem/account-abstraction';
2
5
  import { ec } from 'elliptic';
3
6
 
@@ -8,7 +11,7 @@ declare function useVerifyAccount(): (pid: string, campaignId: string, dbAuthTok
8
11
 
9
12
  declare function useVerifyWeb3AuthSession(): (idToken: string, publicKey: string, authServiceBaseUrl: string) => Promise<any>;
10
13
 
11
- declare function useCreateWeb3Account(): (idToken: string, publicKey: string, userPid: string, authServiceBaseUrl: string, baseWalletAddress: string, requestedContext: string) => Promise<any>;
14
+ declare function useCreateWeb3Account(): (authToken: string, userPid: string, authServiceBaseUrl: string, baseWalletAddress: string, requestedContext: string) => Promise<any>;
12
15
 
13
16
  declare function useFetchUserData(): (dbAuthToken: string, endpoint: string, pid: string) => Promise<any>;
14
17
 
@@ -50,6 +53,361 @@ declare function useUpdateUserName(): (dbAuthToken: string, docID: string, name:
50
53
  */
51
54
  declare function useFetchNotifications(): (pid: string, dbAuthToken: string, endpoint: string, additionalFilters?: Record<string, any>) => Promise<any>;
52
55
 
56
+ declare function useSendCoinbaseUserOperation(): {
57
+ sendOperationFn: (evmAddress: `0x${string}`, callData: any, contractAddress: `0x${string}`) => Promise<{
58
+ success: boolean;
59
+ message: string;
60
+ }>;
61
+ data: _coinbase_cdp_api_client.EvmUserOperation | undefined;
62
+ status: _coinbase_cdp_hooks.Status;
63
+ error: Error | undefined;
64
+ };
65
+
66
+ declare const PET_NFT_ABI: ({
67
+ inputs: never[];
68
+ stateMutability: string;
69
+ type: string;
70
+ name?: undefined;
71
+ anonymous?: undefined;
72
+ outputs?: undefined;
73
+ } | {
74
+ inputs: {
75
+ internalType: string;
76
+ name: string;
77
+ type: string;
78
+ }[];
79
+ name: string;
80
+ type: string;
81
+ stateMutability?: undefined;
82
+ anonymous?: undefined;
83
+ outputs?: undefined;
84
+ } | {
85
+ anonymous: boolean;
86
+ inputs: {
87
+ indexed: boolean;
88
+ internalType: string;
89
+ name: string;
90
+ type: string;
91
+ }[];
92
+ name: string;
93
+ type: string;
94
+ stateMutability?: undefined;
95
+ outputs?: undefined;
96
+ } | {
97
+ inputs: {
98
+ internalType: string;
99
+ name: string;
100
+ type: string;
101
+ }[];
102
+ name: string;
103
+ outputs: {
104
+ internalType: string;
105
+ name: string;
106
+ type: string;
107
+ }[];
108
+ stateMutability: string;
109
+ type: string;
110
+ anonymous?: undefined;
111
+ })[];
112
+ declare const MARKETPLACE_ABI: ({
113
+ inputs: {
114
+ internalType: string;
115
+ name: string;
116
+ type: string;
117
+ }[];
118
+ name: string;
119
+ type: string;
120
+ anonymous?: undefined;
121
+ outputs?: undefined;
122
+ stateMutability?: undefined;
123
+ } | {
124
+ anonymous: boolean;
125
+ inputs: {
126
+ indexed: boolean;
127
+ internalType: string;
128
+ name: string;
129
+ type: string;
130
+ }[];
131
+ name: string;
132
+ type: string;
133
+ outputs?: undefined;
134
+ stateMutability?: undefined;
135
+ } | {
136
+ inputs: {
137
+ internalType: string;
138
+ name: string;
139
+ type: string;
140
+ }[];
141
+ name: string;
142
+ outputs: {
143
+ internalType: string;
144
+ name: string;
145
+ type: string;
146
+ }[];
147
+ stateMutability: string;
148
+ type: string;
149
+ anonymous?: undefined;
150
+ })[];
151
+ declare const ORGANIZATION_BEACON_ABI: ({
152
+ inputs: {
153
+ internalType: string;
154
+ name: string;
155
+ type: string;
156
+ }[];
157
+ stateMutability: string;
158
+ type: string;
159
+ name?: undefined;
160
+ anonymous?: undefined;
161
+ outputs?: undefined;
162
+ } | {
163
+ inputs: {
164
+ internalType: string;
165
+ name: string;
166
+ type: string;
167
+ }[];
168
+ name: string;
169
+ type: string;
170
+ stateMutability?: undefined;
171
+ anonymous?: undefined;
172
+ outputs?: undefined;
173
+ } | {
174
+ anonymous: boolean;
175
+ inputs: {
176
+ indexed: boolean;
177
+ internalType: string;
178
+ name: string;
179
+ type: string;
180
+ }[];
181
+ name: string;
182
+ type: string;
183
+ stateMutability?: undefined;
184
+ outputs?: undefined;
185
+ } | {
186
+ inputs: {
187
+ internalType: string;
188
+ name: string;
189
+ type: string;
190
+ }[];
191
+ name: string;
192
+ outputs: {
193
+ internalType: string;
194
+ name: string;
195
+ type: string;
196
+ }[];
197
+ stateMutability: string;
198
+ type: string;
199
+ anonymous?: undefined;
200
+ })[];
201
+ declare const REWARDABLE_ACTIONS_ABI: ({
202
+ inputs: never[];
203
+ stateMutability: string;
204
+ type: string;
205
+ name?: undefined;
206
+ anonymous?: undefined;
207
+ outputs?: undefined;
208
+ } | {
209
+ inputs: {
210
+ internalType: string;
211
+ name: string;
212
+ type: string;
213
+ }[];
214
+ name: string;
215
+ type: string;
216
+ stateMutability?: undefined;
217
+ anonymous?: undefined;
218
+ outputs?: undefined;
219
+ } | {
220
+ anonymous: boolean;
221
+ inputs: {
222
+ indexed: boolean;
223
+ internalType: string;
224
+ name: string;
225
+ type: string;
226
+ }[];
227
+ name: string;
228
+ type: string;
229
+ stateMutability?: undefined;
230
+ outputs?: undefined;
231
+ } | {
232
+ inputs: {
233
+ internalType: string;
234
+ name: string;
235
+ type: string;
236
+ }[];
237
+ name: string;
238
+ outputs: {
239
+ internalType: string;
240
+ name: string;
241
+ type: string;
242
+ }[];
243
+ stateMutability: string;
244
+ type: string;
245
+ anonymous?: undefined;
246
+ })[];
247
+ declare const ORGANIZATION_IMPL_ABI: ({
248
+ inputs: never[];
249
+ stateMutability: string;
250
+ type: string;
251
+ name?: undefined;
252
+ anonymous?: undefined;
253
+ outputs?: undefined;
254
+ } | {
255
+ inputs: {
256
+ internalType: string;
257
+ name: string;
258
+ type: string;
259
+ }[];
260
+ name: string;
261
+ type: string;
262
+ stateMutability?: undefined;
263
+ anonymous?: undefined;
264
+ outputs?: undefined;
265
+ } | {
266
+ anonymous: boolean;
267
+ inputs: {
268
+ indexed: boolean;
269
+ internalType: string;
270
+ name: string;
271
+ type: string;
272
+ }[];
273
+ name: string;
274
+ type: string;
275
+ stateMutability?: undefined;
276
+ outputs?: undefined;
277
+ } | {
278
+ inputs: {
279
+ internalType: string;
280
+ name: string;
281
+ type: string;
282
+ }[];
283
+ name: string;
284
+ outputs: {
285
+ internalType: string;
286
+ name: string;
287
+ type: string;
288
+ }[];
289
+ stateMutability: string;
290
+ type: string;
291
+ anonymous?: undefined;
292
+ })[];
293
+ declare const KIBBLE_TOKEN_ABI: ({
294
+ inputs: never[];
295
+ stateMutability: string;
296
+ type: string;
297
+ name?: undefined;
298
+ anonymous?: undefined;
299
+ outputs?: undefined;
300
+ } | {
301
+ inputs: {
302
+ internalType: string;
303
+ name: string;
304
+ type: string;
305
+ }[];
306
+ name: string;
307
+ type: string;
308
+ stateMutability?: undefined;
309
+ anonymous?: undefined;
310
+ outputs?: undefined;
311
+ } | {
312
+ anonymous: boolean;
313
+ inputs: {
314
+ indexed: boolean;
315
+ internalType: string;
316
+ name: string;
317
+ type: string;
318
+ }[];
319
+ name: string;
320
+ type: string;
321
+ stateMutability?: undefined;
322
+ outputs?: undefined;
323
+ } | {
324
+ inputs: {
325
+ internalType: string;
326
+ name: string;
327
+ type: string;
328
+ }[];
329
+ name: string;
330
+ outputs: {
331
+ internalType: string;
332
+ name: string;
333
+ type: string;
334
+ }[];
335
+ stateMutability: string;
336
+ type: string;
337
+ anonymous?: undefined;
338
+ } | {
339
+ inputs: {
340
+ internalType: string;
341
+ name: string;
342
+ type: string;
343
+ }[];
344
+ name: string;
345
+ outputs: {
346
+ components: {
347
+ internalType: string;
348
+ name: string;
349
+ type: string;
350
+ }[];
351
+ internalType: string;
352
+ name: string;
353
+ type: string;
354
+ }[];
355
+ stateMutability: string;
356
+ type: string;
357
+ anonymous?: undefined;
358
+ })[];
359
+ declare const ERROR_ABI: ({
360
+ inputs: {
361
+ internalType: string;
362
+ name: string;
363
+ type: string;
364
+ }[];
365
+ name: string;
366
+ type: string;
367
+ stateMutability?: undefined;
368
+ anonymous?: undefined;
369
+ outputs?: undefined;
370
+ } | {
371
+ anonymous: boolean;
372
+ inputs: {
373
+ indexed: boolean;
374
+ internalType: string;
375
+ name: string;
376
+ type: string;
377
+ }[];
378
+ name: string;
379
+ type: string;
380
+ stateMutability?: undefined;
381
+ outputs?: undefined;
382
+ } | {
383
+ inputs: {
384
+ internalType: string;
385
+ name: string;
386
+ type: string;
387
+ }[];
388
+ name: string;
389
+ outputs: {
390
+ internalType: string;
391
+ name: string;
392
+ type: string;
393
+ }[];
394
+ stateMutability: string;
395
+ type: string;
396
+ anonymous?: undefined;
397
+ } | {
398
+ inputs: {
399
+ internalType: string;
400
+ name: string;
401
+ type: string;
402
+ }[];
403
+ stateMutability: string;
404
+ type: string;
405
+ name?: undefined;
406
+ anonymous?: undefined;
407
+ outputs?: undefined;
408
+ } | abitype.Abi)[];
409
+ declare const ORG_FUNCTION = "executeCall";
410
+
53
411
  declare function useMintAnymalNFT(): (pid: string, nftId: string, anymalTxId: string, dbAuthToken: string, validationContractAddress: string, smartAccount: any, bundlerClient: any) => Promise<{
54
412
  success: boolean;
55
413
  message: string;
@@ -507,4 +865,4 @@ declare function useSubmitContractAction(): (idToken: string, pid: string, sourc
507
865
  */
508
866
  declare function humanRevert(raw: `0x${string}` | undefined, shortMessage?: string): string;
509
867
 
510
- export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, type ActionReferral, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, type ExternalActionPayload, FIREBASE_WEB_API_KEYS, FIREBASE_WEB_AUTH_API_ENDPOINTS, type GraphQLActionPayload, type JWTOptions, type MarketplaceActionPayload, MarketplacePaymentType, NETWORK_HOSTS, Network, type NotificationData, type NotificationEventData, type SubmitResponse, type WishlistPurchaseActionPayload, convertToActionDefinition, convertToActionRecord, convertToMultipleActionDefinitions, convertToMultipleActionRecords, createApp, createAuthEnvelope, fetchAnymals, flattenFirestoreData, generateAppSignature, generateBytes32Nonce, generateJWT, getFirebaseTokenForApp, humanRevert, loadExistingSecp256k1PrivateKey, processDirectKibbleApproval, processDirectPartialPayment, processOrgKibbleApproval, processOrgPartialPayment, sendUserOpWithRetries, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useMintOrgAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useSubmitContractAction, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession, waitForAllowance, waitForReceiptWithRetries };
868
+ export { AUTH_API_ENDPOINTS, type ActionDefinition, type ActionPayload, type ActionRecord, type ActionReferral, ActionSourceType, ActionStatus, ActionType, type AnymalNftMetadataInputData, type AuthEnvelope, type ContractActionPayload, type CreateAnymalInputData, ERROR_ABI, type ExternalActionPayload, FIREBASE_WEB_API_KEYS, FIREBASE_WEB_AUTH_API_ENDPOINTS, type GraphQLActionPayload, type JWTOptions, KIBBLE_TOKEN_ABI, MARKETPLACE_ABI, type MarketplaceActionPayload, MarketplacePaymentType, NETWORK_HOSTS, Network, type NotificationData, type NotificationEventData, ORGANIZATION_BEACON_ABI, ORGANIZATION_IMPL_ABI, ORG_FUNCTION, PET_NFT_ABI, REWARDABLE_ACTIONS_ABI, type SubmitResponse, type WishlistPurchaseActionPayload, convertToActionDefinition, convertToActionRecord, convertToMultipleActionDefinitions, convertToMultipleActionRecords, createApp, createAuthEnvelope, fetchAnymals, flattenFirestoreData, generateAppSignature, generateBytes32Nonce, generateJWT, getFirebaseTokenForApp, humanRevert, loadExistingSecp256k1PrivateKey, processDirectKibbleApproval, processDirectPartialPayment, processOrgKibbleApproval, processOrgPartialPayment, sendUserOpWithRetries, serializePublicKeyCompressed, submitAction, useAddAnymalToDatabase, useApproveKibbleToken, useApproveOrgPartialPayment, useClaimActionReward, useClaimOrgActionReward, useCreateOrganizationAppData, useCreateOrganizationBase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchActionDefinitions, useFetchActions, useFetchAnymals, useFetchBalance, useFetchNotifications, useFetchUserData, useMintAnymalNFT, useMintOrgAnymalNFT, useProcessOrgPartialKibblePayment, useProcessPartialKibblePayment, useSaveAnymalMetadata, useSendCoinbaseUserOperation, useSubmitContractAction, useUpdateAnymalWithNFT, useUpdateOrgWalletAddress, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession, waitForAllowance, waitForReceiptWithRetries };