@settlemint/sdk-js 2.1.1-mainb520d1f5 → 2.1.1-mainc0c9792e

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`](#settlemintclient)
63
63
 
64
- Defined in: [settlemint.ts:216](https://github.com/settlemint/sdk/blob/v2.1.1/sdk/js/src/settlemint.ts#L216)
64
+ Defined in: [settlemint.ts:223](https://github.com/settlemint/sdk/blob/v2.1.1/sdk/js/src/settlemint.ts#L223)
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:111](https://github.com/settlemint/sdk/blob/v2.1.1/sdk/js/src/settlemint.ts#L111)
111
+ Defined in: [settlemint.ts:117](https://github.com/settlemint/sdk/blob/v2.1.1/sdk/js/src/settlemint.ts#L117)
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:103](https://github.com/settlemint/sdk/blob/v2.1.1/sdk/js/src/settlemint.ts#L103)
119
+ Defined in: [settlemint.ts:109](https://github.com/settlemint/sdk/blob/v2.1.1/sdk/js/src/settlemint.ts#L109)
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/v2.1.1/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:105](https://github.com/settlemint/sdk/blob/v2.1.1/sdk/js/src/settlemint.ts#L105) |
132
+ | <a id="anonymous"></a> `anonymous?` | `boolean` | `undefined` | Whether to allow anonymous access (no access token required) | - | [settlemint.ts:111](https://github.com/settlemint/sdk/blob/v2.1.1/sdk/js/src/settlemint.ts#L111) |
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/v2.1.1/sdk/js/src/helpers/client-options.schema.ts#L11) |
134
134
 
135
135
  ### Type Aliases
@@ -1546,26 +1546,20 @@ function generateResponse(pincode, salt, challenge) {
1546
1546
  const hashedPincode = hashPincode(pincode, salt);
1547
1547
  return (0, import_node_crypto.createHash)("sha256").update(`${hashedPincode}_${challenge}`).digest("hex");
1548
1548
  }
1549
- async function getPincodeVerificationResponse({
1549
+ async function getPincodeVerificationChallenges({
1550
1550
  userWalletAddress,
1551
- pincode,
1552
1551
  accessToken,
1553
1552
  instance,
1554
1553
  nodeId
1555
1554
  }) {
1556
1555
  const response = await fetch(
1557
- `${instance}/cm/nodes/${encodeURIComponent(nodeId)}/user-wallets/${encodeURIComponent(userWalletAddress)}/verifications/challenges`,
1556
+ `${instance}/cm/nodes/${encodeURIComponent(nodeId)}/user-wallets/${encodeURIComponent(userWalletAddress)}/verifications/challenges?type=PINCODE`,
1558
1557
  {
1559
1558
  method: "POST",
1560
1559
  headers: {
1561
1560
  "Content-Type": "application/json",
1562
1561
  "x-auth-token": accessToken
1563
- },
1564
- body: JSON.stringify({
1565
- pincode,
1566
- verificationType: "PINCODE",
1567
- name: "pincode"
1568
- })
1562
+ }
1569
1563
  }
1570
1564
  );
1571
1565
  if (!response.ok) {
@@ -1575,15 +1569,16 @@ async function getPincodeVerificationResponse({
1575
1569
  throw new Error("Failed to get verification challenge");
1576
1570
  }
1577
1571
  const verificationChallenges = await response.json();
1578
- if (!verificationChallenges.length) {
1579
- throw new Error("No verification challenges received");
1580
- }
1581
- const firstChallenge = verificationChallenges[0];
1582
- const challenge = firstChallenge?.challenge;
1583
- if (!challenge?.secret || !challenge?.salt) {
1572
+ return verificationChallenges;
1573
+ }
1574
+ function getPincodeVerificationChallengeResponse({
1575
+ verificationChallenge,
1576
+ pincode
1577
+ }) {
1578
+ if (!verificationChallenge?.challenge?.secret || !verificationChallenge?.challenge?.salt) {
1584
1579
  throw new Error("Could not authenticate pin code, invalid challenge format");
1585
1580
  }
1586
- const { secret, salt } = challenge;
1581
+ const { secret, salt } = verificationChallenge.challenge;
1587
1582
  return generateResponse(pincode, salt, secret);
1588
1583
  }
1589
1584
 
@@ -1690,7 +1685,8 @@ function createSettleMintClient(options) {
1690
1685
  config: getPlatformConfig(gqlClient)
1691
1686
  },
1692
1687
  wallet: {
1693
- pincodeVerificationResponse: (args) => getPincodeVerificationResponse({
1688
+ pincodeVerificationChallengeResponse: getPincodeVerificationChallengeResponse,
1689
+ pincodeVerificationChallenges: (args) => getPincodeVerificationChallenges({
1694
1690
  ...args,
1695
1691
  instance: validatedOptions.instance,
1696
1692
  accessToken: validatedOptions.accessToken