@orangecheck/me-client 0.56.0 → 0.57.0

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/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { isDidOc } from '@orangecheck/auth-core/identifiers';
2
+
1
3
  var __defProp = Object.defineProperty;
2
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
5
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -44,7 +46,7 @@ async function api(path, opts = {}) {
44
46
  body = data;
45
47
  if (data?.error) {
46
48
  errorCode = data.error;
47
- message = data.reason ?? data.error;
49
+ message = data.reason ?? data.detail ?? data.error;
48
50
  }
49
51
  } catch {
50
52
  }
@@ -1296,8 +1298,6 @@ async function defaultLive() {
1296
1298
  return all[0] ?? null;
1297
1299
  }
1298
1300
  var federations = { list, live, get, defaultLive };
1299
-
1300
- // src/scope.ts
1301
1301
  var CONSENT_ORIGIN = "https://ochk.app";
1302
1302
  var VALID_SCOPES = [
1303
1303
  "bitcoin_address",
@@ -1324,9 +1324,28 @@ async function granted(options) {
1324
1324
  if (!options.project_key) {
1325
1325
  throw new Error("oc.scope.granted: project_key is required");
1326
1326
  }
1327
+ const { accountId, signingSecret } = options;
1328
+ if (accountId !== void 0 && !signingSecret) {
1329
+ throw new Error("oc.scope.granted: accountId names the person, so it requires signingSecret");
1330
+ }
1331
+ if (signingSecret && accountId === void 0) {
1332
+ throw new Error("oc.scope.granted: signingSecret signs a question about one person, so it requires accountId");
1333
+ }
1334
+ if (accountId !== void 0 && !isDidOc(accountId)) {
1335
+ throw new Error("oc.scope.granted: accountId must be a did:oc exactly as issued (did:oc: and 32 lowercase hex)");
1336
+ }
1337
+ let path = `/api/integrator/scopes/${encodeURIComponent(options.project_key)}`;
1338
+ const headers = {};
1339
+ if (accountId !== void 0 && signingSecret) {
1340
+ path += `?user=${encodeURIComponent(accountId)}`;
1341
+ headers["x-oc-signature"] = await signBody(
1342
+ signingSecret,
1343
+ `project_key=${options.project_key}&user=${accountId}`
1344
+ );
1345
+ }
1327
1346
  const r = await api(
1328
- `/api/integrator/scopes/${encodeURIComponent(options.project_key)}`,
1329
- { method: "GET", signal: options.signal }
1347
+ path,
1348
+ { method: "GET", signal: options.signal, headers }
1330
1349
  );
1331
1350
  return {
1332
1351
  sub: r.sub,