@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.
- package/dist/settlemint.cjs +45 -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 +45 -51
- package/dist/settlemint.mjs.map +1 -1
- package/package.json +2 -2
package/dist/settlemint.cjs
CHANGED
|
@@ -29,6 +29,50 @@ var import_validation3 = require("@settlemint/sdk-utils/validation");
|
|
|
29
29
|
var import_graphql_request = require("graphql-request");
|
|
30
30
|
var import_zod2 = require("zod");
|
|
31
31
|
|
|
32
|
+
// src/challenge.ts
|
|
33
|
+
var import_node_crypto = require("crypto");
|
|
34
|
+
function hashPincode(pincode, salt) {
|
|
35
|
+
return (0, import_node_crypto.createHash)("sha256").update(`${salt}${pincode}`).digest("hex");
|
|
36
|
+
}
|
|
37
|
+
function generateChallengeResponse(pincode, salt, challenge) {
|
|
38
|
+
const hashedPincode = hashPincode(pincode, salt);
|
|
39
|
+
return (0, import_node_crypto.createHash)("sha256").update(`${hashedPincode}_${challenge}`).digest("hex");
|
|
40
|
+
}
|
|
41
|
+
async function handleChallenge({
|
|
42
|
+
userWalletAddress,
|
|
43
|
+
pincode,
|
|
44
|
+
accessToken,
|
|
45
|
+
instance,
|
|
46
|
+
nodeId
|
|
47
|
+
}) {
|
|
48
|
+
const response = await fetch(`${instance}/cm/nodes/${nodeId}/${userWalletAddress}/verifications`, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
"x-auth-token": accessToken
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
pincode,
|
|
56
|
+
verificationType: "PINCODE",
|
|
57
|
+
name: "pincode"
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
throw new Error("Failed to handle challenge");
|
|
62
|
+
}
|
|
63
|
+
const verificationChallenges = await response.json();
|
|
64
|
+
if (!verificationChallenges.length) {
|
|
65
|
+
throw new Error("No verification challenges received");
|
|
66
|
+
}
|
|
67
|
+
const firstChallenge = verificationChallenges[0];
|
|
68
|
+
const challenge = firstChallenge?.challenge;
|
|
69
|
+
if (!challenge?.secret || !challenge?.salt) {
|
|
70
|
+
throw new Error("Could not authenticate pin code, invalid challenge format");
|
|
71
|
+
}
|
|
72
|
+
const { secret, salt } = challenge;
|
|
73
|
+
return generateChallengeResponse(pincode, salt, secret);
|
|
74
|
+
}
|
|
75
|
+
|
|
32
76
|
// src/helpers/graphql.ts
|
|
33
77
|
var import_gql = require("gql.tada");
|
|
34
78
|
var import_gql2 = require("gql.tada");
|
|
@@ -1527,56 +1571,6 @@ var ClientOptionsSchema = import_zod.z.object({
|
|
|
1527
1571
|
instance: import_validation2.UrlSchema
|
|
1528
1572
|
});
|
|
1529
1573
|
|
|
1530
|
-
// src/pincode-verification.ts
|
|
1531
|
-
var import_node_crypto = require("crypto");
|
|
1532
|
-
function hashPincode(pincode, salt) {
|
|
1533
|
-
return (0, import_node_crypto.createHash)("sha256").update(`${salt}${pincode}`).digest("hex");
|
|
1534
|
-
}
|
|
1535
|
-
function generateResponse(pincode, salt, challenge) {
|
|
1536
|
-
const hashedPincode = hashPincode(pincode, salt);
|
|
1537
|
-
return (0, import_node_crypto.createHash)("sha256").update(`${hashedPincode}_${challenge}`).digest("hex");
|
|
1538
|
-
}
|
|
1539
|
-
async function getPincodeVerificationResponse({
|
|
1540
|
-
userWalletAddress,
|
|
1541
|
-
pincode,
|
|
1542
|
-
accessToken,
|
|
1543
|
-
instance,
|
|
1544
|
-
nodeId
|
|
1545
|
-
}) {
|
|
1546
|
-
const response = await fetch(
|
|
1547
|
-
`${instance}/cm/nodes/${encodeURIComponent(nodeId)}/user-wallets/${encodeURIComponent(userWalletAddress)}/verifications/challenges`,
|
|
1548
|
-
{
|
|
1549
|
-
method: "POST",
|
|
1550
|
-
headers: {
|
|
1551
|
-
"Content-Type": "application/json",
|
|
1552
|
-
"x-auth-token": accessToken
|
|
1553
|
-
},
|
|
1554
|
-
body: JSON.stringify({
|
|
1555
|
-
pincode,
|
|
1556
|
-
verificationType: "PINCODE",
|
|
1557
|
-
name: "pincode"
|
|
1558
|
-
})
|
|
1559
|
-
}
|
|
1560
|
-
);
|
|
1561
|
-
if (!response.ok) {
|
|
1562
|
-
if (response.status === 404) {
|
|
1563
|
-
throw new Error(`No user wallet found with address '${userWalletAddress}' for node '${nodeId}'`);
|
|
1564
|
-
}
|
|
1565
|
-
throw new Error("Failed to get verification challenge");
|
|
1566
|
-
}
|
|
1567
|
-
const verificationChallenges = await response.json();
|
|
1568
|
-
if (!verificationChallenges.length) {
|
|
1569
|
-
throw new Error("No verification challenges received");
|
|
1570
|
-
}
|
|
1571
|
-
const firstChallenge = verificationChallenges[0];
|
|
1572
|
-
const challenge = firstChallenge?.challenge;
|
|
1573
|
-
if (!challenge?.secret || !challenge?.salt) {
|
|
1574
|
-
throw new Error("Could not authenticate pin code, invalid challenge format");
|
|
1575
|
-
}
|
|
1576
|
-
const { secret, salt } = challenge;
|
|
1577
|
-
return generateResponse(pincode, salt, secret);
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
1574
|
// src/settlemint.ts
|
|
1581
1575
|
function createSettleMintClient(options) {
|
|
1582
1576
|
(0, import_runtime.ensureServer)();
|
|
@@ -1680,7 +1674,7 @@ function createSettleMintClient(options) {
|
|
|
1680
1674
|
config: getPlatformConfig(gqlClient)
|
|
1681
1675
|
},
|
|
1682
1676
|
wallet: {
|
|
1683
|
-
|
|
1677
|
+
handleChallenge: (args) => handleChallenge({
|
|
1684
1678
|
...args,
|
|
1685
1679
|
instance: validatedOptions.instance,
|
|
1686
1680
|
accessToken: validatedOptions.accessToken
|