@settlemint/sdk-js 1.1.3-prf5602d46 → 1.1.3-prfe56c41b

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 CHANGED
@@ -61,7 +61,7 @@ The SettleMint JavaScript SDK provides a type-safe wrapper around the SettleMint
61
61
 
62
62
  > **createSettleMintClient**(`options`): [`SettlemintClient`](README.md#settlemintclient)
63
63
 
64
- Defined in: [settlemint.ts:210](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/settlemint.ts#L210)
64
+ Defined in: [settlemint.ts:216](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/settlemint.ts#L216)
65
65
 
66
66
  Creates a SettleMint client with the provided options. The client provides methods to interact with
67
67
  various SettleMint resources like workspaces, applications, blockchain networks, blockchain nodes, middleware,
@@ -108,7 +108,7 @@ const workspace = await client.workspace.read('workspace-unique-name');
108
108
 
109
109
  #### SettlemintClient
110
110
 
111
- Defined in: [settlemint.ts:110](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/settlemint.ts#L110)
111
+ Defined in: [settlemint.ts:111](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/settlemint.ts#L111)
112
112
 
113
113
  Client interface for interacting with the SettleMint platform.
114
114
 
@@ -116,7 +116,7 @@ Client interface for interacting with the SettleMint platform.
116
116
 
117
117
  #### SettlemintClientOptions
118
118
 
119
- Defined in: [settlemint.ts:102](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/settlemint.ts#L102)
119
+ Defined in: [settlemint.ts:103](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/settlemint.ts#L103)
120
120
 
121
121
  Options for the Settlemint client.
122
122
 
@@ -129,7 +129,7 @@ Options for the Settlemint client.
129
129
  | Property | Type | Default value | Description | Inherited from | Defined in |
130
130
  | ------ | ------ | ------ | ------ | ------ | ------ |
131
131
  | <a id="accesstoken"></a> `accessToken` | `string` | `AccessTokenSchema` | The access token used to authenticate with the SettleMint platform | `ClientOptions.accessToken` | [helpers/client-options.schema.ts:9](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/helpers/client-options.schema.ts#L9) |
132
- | <a id="anonymous"></a> `anonymous?` | `boolean` | `undefined` | Whether to allow anonymous access (no access token required) | - | [settlemint.ts:104](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/settlemint.ts#L104) |
132
+ | <a id="anonymous"></a> `anonymous?` | `boolean` | `undefined` | Whether to allow anonymous access (no access token required) | - | [settlemint.ts:105](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/settlemint.ts#L105) |
133
133
  | <a id="instance"></a> `instance` | `string` | `UrlSchema` | The URL of the SettleMint instance to connect to | `ClientOptions.instance` | [helpers/client-options.schema.ts:11](https://github.com/settlemint/sdk/blob/v1.1.3/sdk/js/src/helpers/client-options.schema.ts#L11) |
134
134
 
135
135
  ### Type Aliases
@@ -29,56 +29,6 @@ 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(
49
- `${instance}/cm/nodes/${encodeURIComponent(nodeId)}/user-wallets/${encodeURIComponent(userWalletAddress)}/verifications/challenges`,
50
- {
51
- method: "POST",
52
- headers: {
53
- "Content-Type": "application/json",
54
- "x-auth-token": accessToken
55
- },
56
- body: JSON.stringify({
57
- pincode,
58
- verificationType: "PINCODE",
59
- name: "pincode"
60
- })
61
- }
62
- );
63
- if (!response.ok) {
64
- if (response.status === 404) {
65
- throw new Error(`No user wallet found with address '${userWalletAddress}' for node '${nodeId}'`);
66
- }
67
- throw new Error("Failed to handle challenge");
68
- }
69
- const verificationChallenges = await response.json();
70
- if (!verificationChallenges.length) {
71
- throw new Error("No verification challenges received");
72
- }
73
- const firstChallenge = verificationChallenges[0];
74
- const challenge = firstChallenge?.challenge;
75
- if (!challenge?.secret || !challenge?.salt) {
76
- throw new Error("Could not authenticate pin code, invalid challenge format");
77
- }
78
- const { secret, salt } = challenge;
79
- return generateChallengeResponse(pincode, salt, secret);
80
- }
81
-
82
32
  // src/helpers/graphql.ts
83
33
  var import_gql = require("gql.tada");
84
34
  var import_gql2 = require("gql.tada");
@@ -386,7 +336,7 @@ function setNetworkDefaults(args) {
386
336
  evmStackSize: args.evmStackSize ?? 2048,
387
337
  gasLimit: args.gasLimit ?? "9007199254740991",
388
338
  gasPrice: args.gasPrice ?? 0,
389
- secondsPerBlock: args.secondsPerBlock ?? 15
339
+ secondsPerBlock: args.secondsPerBlock ?? 2
390
340
  };
391
341
  }
392
342
  return clusterServiceArgs;
@@ -1577,6 +1527,56 @@ var ClientOptionsSchema = import_zod.z.object({
1577
1527
  instance: import_validation2.UrlSchema
1578
1528
  });
1579
1529
 
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
1580
  // src/settlemint.ts
1581
1581
  function createSettleMintClient(options) {
1582
1582
  (0, import_runtime.ensureServer)();
@@ -1680,7 +1680,7 @@ function createSettleMintClient(options) {
1680
1680
  config: getPlatformConfig(gqlClient)
1681
1681
  },
1682
1682
  wallet: {
1683
- handleChallenge: (args) => handleChallenge({
1683
+ pincodeVerificationResponse: (args) => getPincodeVerificationResponse({
1684
1684
  ...args,
1685
1685
  instance: validatedOptions.instance,
1686
1686
  accessToken: validatedOptions.accessToken