@settlemint/sdk-js 1.1.3-pr1b1672e8 → 1.1.3-pr5ebbdf33

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.
@@ -5,6 +5,50 @@ import { validate as validate2 } from "@settlemint/sdk-utils/validation";
5
5
  import { GraphQLClient } from "graphql-request";
6
6
  import { z as z2 } from "zod";
7
7
 
8
+ // src/challenge.ts
9
+ import { createHash } from "node:crypto";
10
+ function hashPincode(pincode, salt) {
11
+ return createHash("sha256").update(`${salt}${pincode}`).digest("hex");
12
+ }
13
+ function generateChallengeResponse(pincode, salt, challenge) {
14
+ const hashedPincode = hashPincode(pincode, salt);
15
+ return createHash("sha256").update(`${hashedPincode}_${challenge}`).digest("hex");
16
+ }
17
+ async function handleChallenge({
18
+ userWalletAddress,
19
+ pincode,
20
+ accessToken,
21
+ instance,
22
+ nodeId
23
+ }) {
24
+ const response = await fetch(`${instance}/cm/nodes/${nodeId}/${userWalletAddress}/verifications`, {
25
+ method: "POST",
26
+ headers: {
27
+ "Content-Type": "application/json",
28
+ "x-auth-token": accessToken
29
+ },
30
+ body: JSON.stringify({
31
+ pincode,
32
+ verificationType: "PINCODE",
33
+ name: "pincode"
34
+ })
35
+ });
36
+ if (!response.ok) {
37
+ throw new Error("Failed to handle challenge");
38
+ }
39
+ const verificationChallenges = await response.json();
40
+ if (!verificationChallenges.length) {
41
+ throw new Error("No verification challenges received");
42
+ }
43
+ const firstChallenge = verificationChallenges[0];
44
+ const challenge = firstChallenge?.challenge;
45
+ if (!challenge?.secret || !challenge?.salt) {
46
+ throw new Error("Could not authenticate pin code, invalid challenge format");
47
+ }
48
+ const { secret, salt } = challenge;
49
+ return generateChallengeResponse(pincode, salt, secret);
50
+ }
51
+
8
52
  // src/helpers/graphql.ts
9
53
  import { initGraphQLTada } from "gql.tada";
10
54
  import { readFragment } from "gql.tada";
@@ -1503,56 +1547,6 @@ var ClientOptionsSchema = z.object({
1503
1547
  instance: UrlSchema
1504
1548
  });
1505
1549
 
1506
- // src/pincode-verification.ts
1507
- import { createHash } from "node:crypto";
1508
- function hashPincode(pincode, salt) {
1509
- return createHash("sha256").update(`${salt}${pincode}`).digest("hex");
1510
- }
1511
- function generateResponse(pincode, salt, challenge) {
1512
- const hashedPincode = hashPincode(pincode, salt);
1513
- return createHash("sha256").update(`${hashedPincode}_${challenge}`).digest("hex");
1514
- }
1515
- async function getPincodeVerificationResponse({
1516
- userWalletAddress,
1517
- pincode,
1518
- accessToken,
1519
- instance,
1520
- nodeId
1521
- }) {
1522
- const response = await fetch(
1523
- `${instance}/cm/nodes/${encodeURIComponent(nodeId)}/user-wallets/${encodeURIComponent(userWalletAddress)}/verifications/challenges`,
1524
- {
1525
- method: "POST",
1526
- headers: {
1527
- "Content-Type": "application/json",
1528
- "x-auth-token": accessToken
1529
- },
1530
- body: JSON.stringify({
1531
- pincode,
1532
- verificationType: "PINCODE",
1533
- name: "pincode"
1534
- })
1535
- }
1536
- );
1537
- if (!response.ok) {
1538
- if (response.status === 404) {
1539
- throw new Error(`No user wallet found with address '${userWalletAddress}' for node '${nodeId}'`);
1540
- }
1541
- throw new Error("Failed to get verification challenge");
1542
- }
1543
- const verificationChallenges = await response.json();
1544
- if (!verificationChallenges.length) {
1545
- throw new Error("No verification challenges received");
1546
- }
1547
- const firstChallenge = verificationChallenges[0];
1548
- const challenge = firstChallenge?.challenge;
1549
- if (!challenge?.secret || !challenge?.salt) {
1550
- throw new Error("Could not authenticate pin code, invalid challenge format");
1551
- }
1552
- const { secret, salt } = challenge;
1553
- return generateResponse(pincode, salt, secret);
1554
- }
1555
-
1556
1550
  // src/settlemint.ts
1557
1551
  function createSettleMintClient(options) {
1558
1552
  ensureServer();
@@ -1656,7 +1650,7 @@ function createSettleMintClient(options) {
1656
1650
  config: getPlatformConfig(gqlClient)
1657
1651
  },
1658
1652
  wallet: {
1659
- pincodeVerificationResponse: (args) => getPincodeVerificationResponse({
1653
+ handleChallenge: (args) => handleChallenge({
1660
1654
  ...args,
1661
1655
  instance: validatedOptions.instance,
1662
1656
  accessToken: validatedOptions.accessToken