@tdxvolt/volt-client-grpc 0.20.1 → 0.20.3

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/lib/index.cjs CHANGED
@@ -2735,6 +2735,9 @@ message AuthenticateResponse {
2735
2735
 
2736
2736
  // Reserved for internal use.
2737
2737
  int64 decision_time = 8;
2738
+
2739
+ // Any credentials issued to the client as part of the authentication process.
2740
+ repeated string credential = 9;
2738
2741
  }
2739
2742
 
2740
2743
  message CanAccessResourceRequest {
@@ -4839,6 +4842,11 @@ function issueAuthenticate(authenticateRequest, ttl) {
4839
4842
  authenticateResponse.identity_did;
4840
4843
  }
4841
4844
 
4845
+ this._credential.cache.vc = this._credential.cache.vc || [];
4846
+ for (const credential of authenticateResponse.credential) {
4847
+ this._credential.cache.vc.push(credential);
4848
+ }
4849
+
4842
4850
  this._credential.saveCache();
4843
4851
  break;
4844
4852
  }
@@ -4887,7 +4895,7 @@ function findDIDDocumentService(document, serviceType) {
4887
4895
  return matches;
4888
4896
  }
4889
4897
 
4890
- async function authenticateInternal(noDID = false, ownDID = false) {
4898
+ async function authenticateInternal(noDID = false, ownDID = false, exchangeToken = "") {
4891
4899
  try {
4892
4900
  if (!this._credential.cache.ca) {
4893
4901
  this._credential.cache.ca = this._voltConfig.ca_pem;
@@ -4918,11 +4926,19 @@ async function authenticateInternal(noDID = false, ownDID = false) {
4918
4926
  host: this._credential.cache.bindIp
4919
4927
  };
4920
4928
 
4929
+ if (exchangeToken) {
4930
+ log$2("setting request exchange token");
4931
+ authenticateRequest.exchange_token = exchangeToken;
4932
+ } else {
4933
+ log$2("no exchange token in request");
4934
+ }
4935
+
4921
4936
  if (this._credential.cache.challenge_code) {
4937
+ log$2("setting request challenge code");
4922
4938
  authenticateRequest.challenge = this._credential.cache.challenge_code;
4923
4939
  } else {
4924
4940
  log$2(
4925
- "****challenge code NOT available**** => not sending challenge signature"
4941
+ "no challenge code in request"
4926
4942
  );
4927
4943
  }
4928
4944
 
@@ -5672,9 +5688,10 @@ class VoltClient extends EventEmitter__default["default"] {
5672
5688
  * true if you want to manage the DID yourself
5673
5689
  * @param {boolean} [options.noDID] - whether to create a key-based authentication session
5674
5690
  * instead of a DID-based authentication session.
5691
+ * @param {string} [options.exchangeToken] - optional token to exchange in return for an authenticated session.
5675
5692
  */
5676
5693
  async initialise(config, options = {}) {
5677
- const { ownDID, noDID, didRegistryList, extraConfig } = options;
5694
+ const { ownDID, noDID, didRegistryList, exchangeToken, extraConfig } = options;
5678
5695
  try {
5679
5696
  if (!config) {
5680
5697
  throw new Error(
@@ -5760,7 +5777,7 @@ class VoltClient extends EventEmitter__default["default"] {
5760
5777
  } else {
5761
5778
  // No certificate present in the cache yet => we need to authenticate.
5762
5779
  try {
5763
- isBound = await authenticateInternal.call(this, noDID, ownDID);
5780
+ isBound = await authenticateInternal.call(this, noDID, ownDID, exchangeToken);
5764
5781
  } catch (bindErr) {
5765
5782
  if (bindErr.message === "invalid arguments") {
5766
5783
  // This is usually the result of a missing challenge signature or credential.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.20.1",
6
+ "version": "0.20.3",
7
7
  "description": "tdx Volt library for nodejs clients",
8
8
  "type": "module",
9
9
  "exports": {
@@ -52,6 +52,11 @@ function issueAuthenticate(authenticateRequest, ttl) {
52
52
  authenticateResponse.identity_did;
53
53
  }
54
54
 
55
+ this._credential.cache.vc = this._credential.cache.vc || [];
56
+ for (const credential of authenticateResponse.credential) {
57
+ this._credential.cache.vc.push(credential);
58
+ }
59
+
55
60
  this._credential.saveCache();
56
61
  break;
57
62
  }
@@ -100,7 +105,7 @@ function findDIDDocumentService(document, serviceType) {
100
105
  return matches;
101
106
  }
102
107
 
103
- export async function authenticateInternal(noDID = false, ownDID = false) {
108
+ export async function authenticateInternal(noDID = false, ownDID = false, exchangeToken = "") {
104
109
  try {
105
110
  if (!this._credential.cache.ca) {
106
111
  this._credential.cache.ca = this._voltConfig.ca_pem;
@@ -131,11 +136,19 @@ export async function authenticateInternal(noDID = false, ownDID = false) {
131
136
  host: this._credential.cache.bindIp
132
137
  };
133
138
 
139
+ if (exchangeToken) {
140
+ log("setting request exchange token");
141
+ authenticateRequest.exchange_token = exchangeToken;
142
+ } else {
143
+ log("no exchange token in request");
144
+ }
145
+
134
146
  if (this._credential.cache.challenge_code) {
147
+ log("setting request challenge code");
135
148
  authenticateRequest.challenge = this._credential.cache.challenge_code;
136
149
  } else {
137
150
  log(
138
- "****challenge code NOT available**** => not sending challenge signature"
151
+ "no challenge code in request"
139
152
  );
140
153
  }
141
154
 
@@ -84,9 +84,10 @@ export class VoltClient extends EventEmitter {
84
84
  * true if you want to manage the DID yourself
85
85
  * @param {boolean} [options.noDID] - whether to create a key-based authentication session
86
86
  * instead of a DID-based authentication session.
87
+ * @param {string} [options.exchangeToken] - optional token to exchange in return for an authenticated session.
87
88
  */
88
89
  async initialise(config, options = {}) {
89
- const { ownDID, noDID, didRegistryList, extraConfig } = options;
90
+ const { ownDID, noDID, didRegistryList, exchangeToken, extraConfig } = options;
90
91
  try {
91
92
  if (!config) {
92
93
  throw new Error(
@@ -172,7 +173,7 @@ export class VoltClient extends EventEmitter {
172
173
  } else {
173
174
  // No certificate present in the cache yet => we need to authenticate.
174
175
  try {
175
- isBound = await authenticateInternal.call(this, noDID, ownDID);
176
+ isBound = await authenticateInternal.call(this, noDID, ownDID, exchangeToken);
176
177
  } catch (bindErr) {
177
178
  if (bindErr.message === "invalid arguments") {
178
179
  // This is usually the result of a missing challenge signature or credential.
@@ -2190,6 +2190,9 @@ message AuthenticateResponse {
2190
2190
 
2191
2191
  // Reserved for internal use.
2192
2192
  int64 decision_time = 8;
2193
+
2194
+ // Any credentials issued to the client as part of the authentication process.
2195
+ repeated string credential = 9;
2193
2196
  }
2194
2197
 
2195
2198
  message CanAccessResourceRequest {