@settlemint/sdk-js 1.1.3-prdba810bd → 1.1.3-prf5602d46
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/README.md +4 -4
- package/dist/settlemint.cjs +51 -51
- package/dist/settlemint.cjs.map +1 -1
- package/dist/settlemint.d.cts +9 -9
- package/dist/settlemint.d.ts +9 -9
- package/dist/settlemint.mjs +51 -51
- package/dist/settlemint.mjs.map +1 -1
- package/package.json +2 -2
package/dist/settlemint.mjs
CHANGED
|
@@ -5,6 +5,56 @@ 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(
|
|
25
|
+
`${instance}/cm/nodes/${encodeURIComponent(nodeId)}/user-wallets/${encodeURIComponent(userWalletAddress)}/verifications/challenges`,
|
|
26
|
+
{
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
"x-auth-token": accessToken
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
pincode,
|
|
34
|
+
verificationType: "PINCODE",
|
|
35
|
+
name: "pincode"
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
if (response.status === 404) {
|
|
41
|
+
throw new Error(`No user wallet found with address '${userWalletAddress}' for node '${nodeId}'`);
|
|
42
|
+
}
|
|
43
|
+
throw new Error("Failed to handle challenge");
|
|
44
|
+
}
|
|
45
|
+
const verificationChallenges = await response.json();
|
|
46
|
+
if (!verificationChallenges.length) {
|
|
47
|
+
throw new Error("No verification challenges received");
|
|
48
|
+
}
|
|
49
|
+
const firstChallenge = verificationChallenges[0];
|
|
50
|
+
const challenge = firstChallenge?.challenge;
|
|
51
|
+
if (!challenge?.secret || !challenge?.salt) {
|
|
52
|
+
throw new Error("Could not authenticate pin code, invalid challenge format");
|
|
53
|
+
}
|
|
54
|
+
const { secret, salt } = challenge;
|
|
55
|
+
return generateChallengeResponse(pincode, salt, secret);
|
|
56
|
+
}
|
|
57
|
+
|
|
8
58
|
// src/helpers/graphql.ts
|
|
9
59
|
import { initGraphQLTada } from "gql.tada";
|
|
10
60
|
import { readFragment } from "gql.tada";
|
|
@@ -1503,56 +1553,6 @@ var ClientOptionsSchema = z.object({
|
|
|
1503
1553
|
instance: UrlSchema
|
|
1504
1554
|
});
|
|
1505
1555
|
|
|
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
1556
|
// src/settlemint.ts
|
|
1557
1557
|
function createSettleMintClient(options) {
|
|
1558
1558
|
ensureServer();
|
|
@@ -1656,7 +1656,7 @@ function createSettleMintClient(options) {
|
|
|
1656
1656
|
config: getPlatformConfig(gqlClient)
|
|
1657
1657
|
},
|
|
1658
1658
|
wallet: {
|
|
1659
|
-
|
|
1659
|
+
handleChallenge: (args) => handleChallenge({
|
|
1660
1660
|
...args,
|
|
1661
1661
|
instance: validatedOptions.instance,
|
|
1662
1662
|
accessToken: validatedOptions.accessToken
|