@settlemint/sdk-portal 2.3.2-mainb65cc53b → 2.3.2-maineefa9743

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/portal.d.cts CHANGED
@@ -1,25 +1,22 @@
1
- import { AbstractSetupSchema, FragmentOf, ResultOf, VariablesOf, initGraphQLTada, readFragment } from "gql.tada";
2
- import { GraphQLClient } from "graphql-request";
3
- import { z } from "zod/v4";
4
- import { Address, Hex, TransactionReceipt as TransactionReceipt$1 } from "viem";
5
- import * as graphql_ws0 from "graphql-ws";
1
+ import { AbstractSetupSchema, initGraphQLTada } from 'gql.tada';
2
+ export { FragmentOf, ResultOf, VariablesOf, readFragment } from 'gql.tada';
3
+ import { GraphQLClient } from 'graphql-request';
4
+ import { z } from 'zod/v4';
5
+ import { TransactionReceipt as TransactionReceipt$1, Hex, Address } from 'viem';
6
+ import * as graphql_ws from 'graphql-ws';
6
7
 
7
- //#region src/utils/websocket-client.d.ts
8
- /**
9
- * Options for the GraphQL WebSocket client
10
- */
11
8
  /**
12
9
  * Options for the GraphQL WebSocket client
13
10
  */
14
11
  interface WebsocketClientOptions {
15
- /**
16
- * The GraphQL endpoint URL for the Portal API
17
- */
18
- portalGraphqlEndpoint: string;
19
- /**
20
- * The access token for authentication with the Portal API
21
- */
22
- accessToken?: string;
12
+ /**
13
+ * The GraphQL endpoint URL for the Portal API
14
+ */
15
+ portalGraphqlEndpoint: string;
16
+ /**
17
+ * The access token for authentication with the Portal API
18
+ */
19
+ accessToken?: string;
23
20
  }
24
21
  /**
25
22
  * Creates a GraphQL WebSocket client for the Portal API
@@ -34,61 +31,56 @@ interface WebsocketClientOptions {
34
31
  * accessToken: "your-access-token",
35
32
  * });
36
33
  */
37
- declare function getWebsocketClient({
38
- portalGraphqlEndpoint,
39
- accessToken
40
- }: WebsocketClientOptions): graphql_ws0.Client;
34
+ declare function getWebsocketClient({ portalGraphqlEndpoint, accessToken }: WebsocketClientOptions): graphql_ws.Client;
41
35
 
42
- //#endregion
43
- //#region src/utils/wait-for-transaction-receipt.d.ts
44
36
  /**
45
37
  * Represents an event emitted during a transaction execution
46
38
  */
47
39
  interface TransactionEvent {
48
- /** The name of the event that was emitted */
49
- eventName: string;
50
- /** The arguments emitted by the event */
51
- args: Record<string, unknown>;
52
- /** Indexed event parameters used for filtering and searching */
53
- topics: Hex[];
40
+ /** The name of the event that was emitted */
41
+ eventName: string;
42
+ /** The arguments emitted by the event */
43
+ args: Record<string, unknown>;
44
+ /** Indexed event parameters used for filtering and searching */
45
+ topics: Hex[];
54
46
  }
55
47
  /**
56
48
  * Represents the structure of a blockchain transaction receipt
57
49
  */
58
50
  interface TransactionReceipt extends TransactionReceipt$1<string, number, "Success" | "Reverted"> {
59
- /** The raw reason for transaction reversion, if applicable */
60
- revertReason: string;
61
- /** Human-readable version of the revert reason */
62
- revertReasonDecoded: string;
63
- /** Array of events emitted during the transaction */
64
- events: TransactionEvent[];
65
- /** The address of the contract deployed in the transaction */
66
- contractAddress: Address;
51
+ /** The raw reason for transaction reversion, if applicable */
52
+ revertReason: string;
53
+ /** Human-readable version of the revert reason */
54
+ revertReasonDecoded: string;
55
+ /** Array of events emitted during the transaction */
56
+ events: TransactionEvent[];
57
+ /** The address of the contract deployed in the transaction */
58
+ contractAddress: Address;
67
59
  }
68
60
  /**
69
61
  * Represents the structure of a blockchain transaction with its receipt
70
62
  */
71
63
  interface Transaction {
72
- receipt: TransactionReceipt;
73
- /** The hash of the transaction (duplicate of receipt.transactionHash) */
74
- transactionHash: string;
75
- /** The sender address (duplicate of receipt.from) */
76
- from: string;
77
- /** Timestamp when the transaction was created */
78
- createdAt: string;
79
- /** The contract address involved in the transaction */
80
- address: string;
81
- /** The name of the function called in the transaction */
82
- functionName: string;
83
- /** Whether the transaction is a contract deployment */
84
- isContract: boolean;
64
+ receipt: TransactionReceipt;
65
+ /** The hash of the transaction (duplicate of receipt.transactionHash) */
66
+ transactionHash: string;
67
+ /** The sender address (duplicate of receipt.from) */
68
+ from: string;
69
+ /** Timestamp when the transaction was created */
70
+ createdAt: string;
71
+ /** The contract address involved in the transaction */
72
+ address: string;
73
+ /** The name of the function called in the transaction */
74
+ functionName: string;
75
+ /** Whether the transaction is a contract deployment */
76
+ isContract: boolean;
85
77
  }
86
78
  /**
87
79
  * Options for waiting for a transaction receipt
88
80
  */
89
81
  interface WaitForTransactionReceiptOptions extends WebsocketClientOptions {
90
- /** Optional timeout in milliseconds before the operation fails */
91
- timeout?: number;
82
+ /** Optional timeout in milliseconds before the operation fails */
83
+ timeout?: number;
92
84
  }
93
85
  /**
94
86
  * Waits for a blockchain transaction receipt by subscribing to transaction updates via GraphQL.
@@ -110,31 +102,22 @@ interface WaitForTransactionReceiptOptions extends WebsocketClientOptions {
110
102
  */
111
103
  declare function waitForTransactionReceipt(transactionHash: string, options: WaitForTransactionReceiptOptions): Promise<Transaction>;
112
104
 
113
- //#endregion
114
- //#region src/utils/wallet-verification-challenge.d.ts
115
- /**
116
- * Custom error class for challenge-related errors
117
- */
118
- declare class ChallengeError extends Error {
119
- readonly code: string;
120
- constructor(message: string, code: string);
121
- }
122
105
  /**
123
106
  * Options for handling a wallet verification challenge
124
107
  */
125
108
  interface HandleWalletVerificationChallengeOptions<Setup extends AbstractSetupSchema> {
126
- /** The portal client instance */
127
- portalClient: GraphQLClient;
128
- /** The GraphQL query builder */
129
- portalGraphql: initGraphQLTada<Setup>;
130
- /** The ID of the verification challenge */
131
- verificationId: string;
132
- /** The wallet address to verify */
133
- userWalletAddress: Address;
134
- /** The verification code provided by the user */
135
- code: string | number;
136
- /** The type of verification being performed */
137
- verificationType: "otp" | "secret-code" | "pincode";
109
+ /** The portal client instance */
110
+ portalClient: GraphQLClient;
111
+ /** The GraphQL query builder */
112
+ portalGraphql: initGraphQLTada<Setup>;
113
+ /** The ID of the verification challenge */
114
+ verificationId: string;
115
+ /** The wallet address to verify */
116
+ userWalletAddress: Address;
117
+ /** The verification code provided by the user */
118
+ code: string | number;
119
+ /** The type of verification being performed */
120
+ verificationType: "otp" | "secret-code" | "pincode";
138
121
  }
139
122
  /**
140
123
  * Handles a wallet verification challenge by generating an appropriate response
@@ -160,20 +143,11 @@ interface HandleWalletVerificationChallengeOptions<Setup extends AbstractSetupSc
160
143
  * verificationType: "otp"
161
144
  * });
162
145
  */
163
- declare function handleWalletVerificationChallenge<const Setup extends AbstractSetupSchema>({
164
- portalClient,
165
- portalGraphql,
166
- verificationId,
167
- userWalletAddress,
168
- code,
169
- verificationType
170
- }: HandleWalletVerificationChallengeOptions<Setup>): Promise<{
171
- challengeResponse: string;
172
- verificationId?: string;
146
+ declare function handleWalletVerificationChallenge<const Setup extends AbstractSetupSchema>({ portalClient, portalGraphql, verificationId, userWalletAddress, code, verificationType, }: HandleWalletVerificationChallengeOptions<Setup>): Promise<{
147
+ challengeResponse: string;
148
+ verificationId?: string;
173
149
  }>;
174
150
 
175
- //#endregion
176
- //#region src/portal.d.ts
177
151
  /**
178
152
  * Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.
179
153
  */
@@ -182,16 +156,16 @@ type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
182
156
  * Schema for validating Portal client configuration options.
183
157
  */
184
158
  declare const ClientOptionsSchema: z.ZodObject<{
185
- instance: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
186
- accessToken: z.ZodOptional<z.ZodString>;
187
- cache: z.ZodOptional<z.ZodEnum<{
188
- default: "default";
189
- "force-cache": "force-cache";
190
- "no-cache": "no-cache";
191
- "no-store": "no-store";
192
- "only-if-cached": "only-if-cached";
193
- reload: "reload";
194
- }>>;
159
+ instance: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
160
+ accessToken: z.ZodOptional<z.ZodString>;
161
+ cache: z.ZodOptional<z.ZodEnum<{
162
+ default: "default";
163
+ "force-cache": "force-cache";
164
+ "no-cache": "no-cache";
165
+ "no-store": "no-store";
166
+ "only-if-cached": "only-if-cached";
167
+ reload: "reload";
168
+ }>>;
195
169
  }, z.core.$strip>;
196
170
  /**
197
171
  * Type representing the validated client options.
@@ -243,10 +217,8 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
243
217
  * const result = await portalClient.request(query);
244
218
  */
245
219
  declare function createPortalClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
246
- client: GraphQLClient;
247
- graphql: initGraphQLTada<Setup>;
220
+ client: GraphQLClient;
221
+ graphql: initGraphQLTada<Setup>;
248
222
  };
249
223
 
250
- //#endregion
251
- export { ClientOptions, ClientOptionsSchema, FragmentOf, HandleWalletVerificationChallengeOptions, RequestConfig, ResultOf, Transaction, TransactionEvent, TransactionReceipt, VariablesOf, WaitForTransactionReceiptOptions, WebsocketClientOptions, createPortalClient, getWebsocketClient, handleWalletVerificationChallenge, readFragment, waitForTransactionReceipt };
252
- //# sourceMappingURL=portal.d.cts.map
224
+ export { type ClientOptions, ClientOptionsSchema, type HandleWalletVerificationChallengeOptions, type RequestConfig, type Transaction, type TransactionEvent, type TransactionReceipt, type WaitForTransactionReceiptOptions, type WebsocketClientOptions, createPortalClient, getWebsocketClient, handleWalletVerificationChallenge, waitForTransactionReceipt };
package/dist/portal.d.ts CHANGED
@@ -1,25 +1,22 @@
1
- import { AbstractSetupSchema, FragmentOf, ResultOf, VariablesOf, initGraphQLTada, readFragment } from "gql.tada";
2
- import { GraphQLClient } from "graphql-request";
3
- import { z } from "zod/v4";
4
- import * as graphql_ws0 from "graphql-ws";
5
- import { Address, Hex, TransactionReceipt as TransactionReceipt$1 } from "viem";
1
+ import { AbstractSetupSchema, initGraphQLTada } from 'gql.tada';
2
+ export { FragmentOf, ResultOf, VariablesOf, readFragment } from 'gql.tada';
3
+ import { GraphQLClient } from 'graphql-request';
4
+ import { z } from 'zod/v4';
5
+ import { TransactionReceipt as TransactionReceipt$1, Hex, Address } from 'viem';
6
+ import * as graphql_ws from 'graphql-ws';
6
7
 
7
- //#region src/utils/websocket-client.d.ts
8
- /**
9
- * Options for the GraphQL WebSocket client
10
- */
11
8
  /**
12
9
  * Options for the GraphQL WebSocket client
13
10
  */
14
11
  interface WebsocketClientOptions {
15
- /**
16
- * The GraphQL endpoint URL for the Portal API
17
- */
18
- portalGraphqlEndpoint: string;
19
- /**
20
- * The access token for authentication with the Portal API
21
- */
22
- accessToken?: string;
12
+ /**
13
+ * The GraphQL endpoint URL for the Portal API
14
+ */
15
+ portalGraphqlEndpoint: string;
16
+ /**
17
+ * The access token for authentication with the Portal API
18
+ */
19
+ accessToken?: string;
23
20
  }
24
21
  /**
25
22
  * Creates a GraphQL WebSocket client for the Portal API
@@ -34,61 +31,56 @@ interface WebsocketClientOptions {
34
31
  * accessToken: "your-access-token",
35
32
  * });
36
33
  */
37
- declare function getWebsocketClient({
38
- portalGraphqlEndpoint,
39
- accessToken
40
- }: WebsocketClientOptions): graphql_ws0.Client;
34
+ declare function getWebsocketClient({ portalGraphqlEndpoint, accessToken }: WebsocketClientOptions): graphql_ws.Client;
41
35
 
42
- //#endregion
43
- //#region src/utils/wait-for-transaction-receipt.d.ts
44
36
  /**
45
37
  * Represents an event emitted during a transaction execution
46
38
  */
47
39
  interface TransactionEvent {
48
- /** The name of the event that was emitted */
49
- eventName: string;
50
- /** The arguments emitted by the event */
51
- args: Record<string, unknown>;
52
- /** Indexed event parameters used for filtering and searching */
53
- topics: Hex[];
40
+ /** The name of the event that was emitted */
41
+ eventName: string;
42
+ /** The arguments emitted by the event */
43
+ args: Record<string, unknown>;
44
+ /** Indexed event parameters used for filtering and searching */
45
+ topics: Hex[];
54
46
  }
55
47
  /**
56
48
  * Represents the structure of a blockchain transaction receipt
57
49
  */
58
50
  interface TransactionReceipt extends TransactionReceipt$1<string, number, "Success" | "Reverted"> {
59
- /** The raw reason for transaction reversion, if applicable */
60
- revertReason: string;
61
- /** Human-readable version of the revert reason */
62
- revertReasonDecoded: string;
63
- /** Array of events emitted during the transaction */
64
- events: TransactionEvent[];
65
- /** The address of the contract deployed in the transaction */
66
- contractAddress: Address;
51
+ /** The raw reason for transaction reversion, if applicable */
52
+ revertReason: string;
53
+ /** Human-readable version of the revert reason */
54
+ revertReasonDecoded: string;
55
+ /** Array of events emitted during the transaction */
56
+ events: TransactionEvent[];
57
+ /** The address of the contract deployed in the transaction */
58
+ contractAddress: Address;
67
59
  }
68
60
  /**
69
61
  * Represents the structure of a blockchain transaction with its receipt
70
62
  */
71
63
  interface Transaction {
72
- receipt: TransactionReceipt;
73
- /** The hash of the transaction (duplicate of receipt.transactionHash) */
74
- transactionHash: string;
75
- /** The sender address (duplicate of receipt.from) */
76
- from: string;
77
- /** Timestamp when the transaction was created */
78
- createdAt: string;
79
- /** The contract address involved in the transaction */
80
- address: string;
81
- /** The name of the function called in the transaction */
82
- functionName: string;
83
- /** Whether the transaction is a contract deployment */
84
- isContract: boolean;
64
+ receipt: TransactionReceipt;
65
+ /** The hash of the transaction (duplicate of receipt.transactionHash) */
66
+ transactionHash: string;
67
+ /** The sender address (duplicate of receipt.from) */
68
+ from: string;
69
+ /** Timestamp when the transaction was created */
70
+ createdAt: string;
71
+ /** The contract address involved in the transaction */
72
+ address: string;
73
+ /** The name of the function called in the transaction */
74
+ functionName: string;
75
+ /** Whether the transaction is a contract deployment */
76
+ isContract: boolean;
85
77
  }
86
78
  /**
87
79
  * Options for waiting for a transaction receipt
88
80
  */
89
81
  interface WaitForTransactionReceiptOptions extends WebsocketClientOptions {
90
- /** Optional timeout in milliseconds before the operation fails */
91
- timeout?: number;
82
+ /** Optional timeout in milliseconds before the operation fails */
83
+ timeout?: number;
92
84
  }
93
85
  /**
94
86
  * Waits for a blockchain transaction receipt by subscribing to transaction updates via GraphQL.
@@ -110,31 +102,22 @@ interface WaitForTransactionReceiptOptions extends WebsocketClientOptions {
110
102
  */
111
103
  declare function waitForTransactionReceipt(transactionHash: string, options: WaitForTransactionReceiptOptions): Promise<Transaction>;
112
104
 
113
- //#endregion
114
- //#region src/utils/wallet-verification-challenge.d.ts
115
- /**
116
- * Custom error class for challenge-related errors
117
- */
118
- declare class ChallengeError extends Error {
119
- readonly code: string;
120
- constructor(message: string, code: string);
121
- }
122
105
  /**
123
106
  * Options for handling a wallet verification challenge
124
107
  */
125
108
  interface HandleWalletVerificationChallengeOptions<Setup extends AbstractSetupSchema> {
126
- /** The portal client instance */
127
- portalClient: GraphQLClient;
128
- /** The GraphQL query builder */
129
- portalGraphql: initGraphQLTada<Setup>;
130
- /** The ID of the verification challenge */
131
- verificationId: string;
132
- /** The wallet address to verify */
133
- userWalletAddress: Address;
134
- /** The verification code provided by the user */
135
- code: string | number;
136
- /** The type of verification being performed */
137
- verificationType: "otp" | "secret-code" | "pincode";
109
+ /** The portal client instance */
110
+ portalClient: GraphQLClient;
111
+ /** The GraphQL query builder */
112
+ portalGraphql: initGraphQLTada<Setup>;
113
+ /** The ID of the verification challenge */
114
+ verificationId: string;
115
+ /** The wallet address to verify */
116
+ userWalletAddress: Address;
117
+ /** The verification code provided by the user */
118
+ code: string | number;
119
+ /** The type of verification being performed */
120
+ verificationType: "otp" | "secret-code" | "pincode";
138
121
  }
139
122
  /**
140
123
  * Handles a wallet verification challenge by generating an appropriate response
@@ -160,20 +143,11 @@ interface HandleWalletVerificationChallengeOptions<Setup extends AbstractSetupSc
160
143
  * verificationType: "otp"
161
144
  * });
162
145
  */
163
- declare function handleWalletVerificationChallenge<const Setup extends AbstractSetupSchema>({
164
- portalClient,
165
- portalGraphql,
166
- verificationId,
167
- userWalletAddress,
168
- code,
169
- verificationType
170
- }: HandleWalletVerificationChallengeOptions<Setup>): Promise<{
171
- challengeResponse: string;
172
- verificationId?: string;
146
+ declare function handleWalletVerificationChallenge<const Setup extends AbstractSetupSchema>({ portalClient, portalGraphql, verificationId, userWalletAddress, code, verificationType, }: HandleWalletVerificationChallengeOptions<Setup>): Promise<{
147
+ challengeResponse: string;
148
+ verificationId?: string;
173
149
  }>;
174
150
 
175
- //#endregion
176
- //#region src/portal.d.ts
177
151
  /**
178
152
  * Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.
179
153
  */
@@ -182,16 +156,16 @@ type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
182
156
  * Schema for validating Portal client configuration options.
183
157
  */
184
158
  declare const ClientOptionsSchema: z.ZodObject<{
185
- instance: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
186
- accessToken: z.ZodOptional<z.ZodString>;
187
- cache: z.ZodOptional<z.ZodEnum<{
188
- default: "default";
189
- "force-cache": "force-cache";
190
- "no-cache": "no-cache";
191
- "no-store": "no-store";
192
- "only-if-cached": "only-if-cached";
193
- reload: "reload";
194
- }>>;
159
+ instance: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
160
+ accessToken: z.ZodOptional<z.ZodString>;
161
+ cache: z.ZodOptional<z.ZodEnum<{
162
+ default: "default";
163
+ "force-cache": "force-cache";
164
+ "no-cache": "no-cache";
165
+ "no-store": "no-store";
166
+ "only-if-cached": "only-if-cached";
167
+ reload: "reload";
168
+ }>>;
195
169
  }, z.core.$strip>;
196
170
  /**
197
171
  * Type representing the validated client options.
@@ -243,10 +217,8 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
243
217
  * const result = await portalClient.request(query);
244
218
  */
245
219
  declare function createPortalClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
246
- client: GraphQLClient;
247
- graphql: initGraphQLTada<Setup>;
220
+ client: GraphQLClient;
221
+ graphql: initGraphQLTada<Setup>;
248
222
  };
249
223
 
250
- //#endregion
251
- export { ClientOptions, ClientOptionsSchema, FragmentOf, HandleWalletVerificationChallengeOptions, RequestConfig, ResultOf, Transaction, TransactionEvent, TransactionReceipt, VariablesOf, WaitForTransactionReceiptOptions, WebsocketClientOptions, createPortalClient, getWebsocketClient, handleWalletVerificationChallenge, readFragment, waitForTransactionReceipt };
252
- //# sourceMappingURL=portal.d.ts.map
224
+ export { type ClientOptions, ClientOptionsSchema, type HandleWalletVerificationChallengeOptions, type RequestConfig, type Transaction, type TransactionEvent, type TransactionReceipt, type WaitForTransactionReceiptOptions, type WebsocketClientOptions, createPortalClient, getWebsocketClient, handleWalletVerificationChallenge, waitForTransactionReceipt };
@@ -0,0 +1,186 @@
1
+ // src/portal.ts
2
+ import { appendHeaders } from "@settlemint/sdk-utils/http";
3
+ import { ensureServer } from "@settlemint/sdk-utils/runtime";
4
+ import { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from "@settlemint/sdk-utils/validation";
5
+ import { initGraphQLTada } from "gql.tada";
6
+ import { GraphQLClient } from "graphql-request";
7
+ import { z } from "zod/v4";
8
+ import { readFragment } from "gql.tada";
9
+
10
+ // src/utils/websocket-client.ts
11
+ import { createClient } from "graphql-ws";
12
+ function getWebsocketClient({ portalGraphqlEndpoint, accessToken }) {
13
+ if (!portalGraphqlEndpoint) {
14
+ throw new Error("portalGraphqlEndpoint is required");
15
+ }
16
+ const graphqlEndpoint = setWsProtocol(new URL(portalGraphqlEndpoint));
17
+ return createClient({
18
+ url: `${graphqlEndpoint.protocol}//${graphqlEndpoint.host}/${accessToken}${graphqlEndpoint.pathname}${graphqlEndpoint.search}`
19
+ });
20
+ }
21
+ function setWsProtocol(url) {
22
+ if (url.protocol === "ws:" || url.protocol === "wss:") {
23
+ return url;
24
+ }
25
+ if (url.protocol === "http:") {
26
+ url.protocol = "ws:";
27
+ } else {
28
+ url.protocol = "wss:";
29
+ }
30
+ return url;
31
+ }
32
+
33
+ // src/utils/wait-for-transaction-receipt.ts
34
+ async function waitForTransactionReceipt(transactionHash, options) {
35
+ const wsClient = getWebsocketClient(options);
36
+ const subscription = wsClient.iterate({
37
+ query: `subscription getTransaction($transactionHash: String!) {
38
+ getTransaction(transactionHash: $transactionHash) {
39
+ receipt {
40
+ transactionHash
41
+ to
42
+ status
43
+ from
44
+ type
45
+ revertReason
46
+ revertReasonDecoded
47
+ logs
48
+ events
49
+ contractAddress
50
+ }
51
+ transactionHash
52
+ from
53
+ createdAt
54
+ address
55
+ functionName
56
+ isContract
57
+ }
58
+ }`,
59
+ variables: { transactionHash }
60
+ });
61
+ const promises = [getTransactionFromSubscription(subscription)];
62
+ if (options.timeout) {
63
+ promises.push(createTimeoutPromise(options.timeout));
64
+ }
65
+ return Promise.race(promises);
66
+ }
67
+ function createTimeoutPromise(timeout) {
68
+ return new Promise((_, reject) => {
69
+ setTimeout(() => reject(new Error("Transaction receipt not found")), timeout);
70
+ });
71
+ }
72
+ async function getTransactionFromSubscription(subscription) {
73
+ for await (const result of subscription) {
74
+ if (result?.data?.getTransaction?.receipt) {
75
+ return result.data.getTransaction;
76
+ }
77
+ }
78
+ throw new Error("No transaction found");
79
+ }
80
+
81
+ // src/utils/wallet-verification-challenge.ts
82
+ import { createHash } from "crypto";
83
+ var ChallengeError = class extends Error {
84
+ code;
85
+ constructor(message, code) {
86
+ super(message);
87
+ this.name = "ChallengeError";
88
+ this.code = code;
89
+ }
90
+ };
91
+ function hashPincode(pincode, salt) {
92
+ return createHash("sha256").update(`${salt}${pincode}`).digest("hex");
93
+ }
94
+ function generateResponse(pincode, salt, challenge) {
95
+ const hashedPincode = hashPincode(pincode, salt);
96
+ return createHash("sha256").update(`${hashedPincode}_${challenge}`).digest("hex");
97
+ }
98
+ async function handleWalletVerificationChallenge({
99
+ portalClient,
100
+ portalGraphql,
101
+ verificationId,
102
+ userWalletAddress,
103
+ code,
104
+ verificationType
105
+ }) {
106
+ try {
107
+ if (verificationType === "otp") {
108
+ return {
109
+ challengeResponse: code.toString(),
110
+ verificationId
111
+ };
112
+ }
113
+ if (verificationType === "secret-code") {
114
+ const formattedCode = code.toString().replace(/(.{5})(?=.)/, "$1-");
115
+ return {
116
+ challengeResponse: formattedCode,
117
+ verificationId
118
+ };
119
+ }
120
+ const verificationChallenges = await portalClient.request(
121
+ portalGraphql(`
122
+ mutation CreateWalletVerificationChallenges($userWalletAddress: String!, $verificationId: String!) {
123
+ createWalletVerificationChallenges(userWalletAddress: $userWalletAddress, verificationId: $verificationId) {
124
+ challenge
125
+ id
126
+ name
127
+ verificationType
128
+ }
129
+ }
130
+ `),
131
+ {
132
+ userWalletAddress,
133
+ verificationId
134
+ }
135
+ );
136
+ if (!verificationChallenges.createWalletVerificationChallenges?.length) {
137
+ throw new ChallengeError("No verification challenges received", "NO_CHALLENGES");
138
+ }
139
+ const walletVerificationChallenge = verificationChallenges.createWalletVerificationChallenges.find(
140
+ (challenge) => challenge.id === verificationId
141
+ );
142
+ if (!walletVerificationChallenge?.challenge?.secret || !walletVerificationChallenge?.challenge?.salt) {
143
+ throw new ChallengeError("Invalid challenge format", "INVALID_CHALLENGE");
144
+ }
145
+ const { secret, salt } = walletVerificationChallenge.challenge;
146
+ const challengeResponse = generateResponse(code.toString(), salt, secret);
147
+ return {
148
+ challengeResponse,
149
+ verificationId
150
+ };
151
+ } catch (error) {
152
+ if (error instanceof ChallengeError) {
153
+ throw error;
154
+ }
155
+ throw new ChallengeError("Failed to process wallet verification challenge", "CHALLENGE_PROCESSING_ERROR");
156
+ }
157
+ }
158
+
159
+ // src/portal.ts
160
+ var ClientOptionsSchema = z.object({
161
+ instance: UrlOrPathSchema,
162
+ accessToken: ApplicationAccessTokenSchema.optional(),
163
+ cache: z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
164
+ });
165
+ function createPortalClient(options, clientOptions) {
166
+ ensureServer();
167
+ const validatedOptions = validate(ClientOptionsSchema, options);
168
+ const graphql = initGraphQLTada();
169
+ const fullUrl = new URL(validatedOptions.instance).toString();
170
+ return {
171
+ client: new GraphQLClient(fullUrl, {
172
+ ...clientOptions,
173
+ headers: appendHeaders(clientOptions?.headers, { "x-auth-token": validatedOptions.accessToken })
174
+ }),
175
+ graphql
176
+ };
177
+ }
178
+ export {
179
+ ClientOptionsSchema,
180
+ createPortalClient,
181
+ getWebsocketClient,
182
+ handleWalletVerificationChallenge,
183
+ readFragment,
184
+ waitForTransactionReceipt
185
+ };
186
+ //# sourceMappingURL=portal.mjs.map