@rare-id/platform-kit-web 0.1.0 → 0.1.1

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.d.ts CHANGED
@@ -72,8 +72,7 @@ interface ChallengeStore {
72
72
  consume(nonce: string): Promise<AuthChallenge | null>;
73
73
  }
74
74
  interface ReplayStore {
75
- has(key: string): Promise<boolean>;
76
- put(key: string, expiresAt: number): Promise<void>;
75
+ claim(key: string, expiresAt: number): Promise<boolean>;
77
76
  }
78
77
  interface SessionStore {
79
78
  save(session: PlatformSession): Promise<void>;
@@ -110,8 +109,7 @@ declare class InMemoryChallengeStore implements ChallengeStore {
110
109
  }
111
110
  declare class InMemoryReplayStore implements ReplayStore {
112
111
  private readonly seen;
113
- has(key: string): Promise<boolean>;
114
- put(key: string, expiresAt: number): Promise<void>;
112
+ claim(key: string, expiresAt: number): Promise<boolean>;
115
113
  private cleanup;
116
114
  }
117
115
  declare class InMemorySessionStore implements SessionStore {
package/dist/index.js CHANGED
@@ -121,10 +121,9 @@ function createRarePlatformKit(config) {
121
121
  throw new Error("delegation replay fields missing");
122
122
  }
123
123
  const delegationReplayKey = `delegation:${jti}`;
124
- if (await config.replayStore.has(delegationReplayKey)) {
124
+ if (!await config.replayStore.claim(delegationReplayKey, exp)) {
125
125
  throw new Error("delegation token replay detected");
126
126
  }
127
- await config.replayStore.put(delegationReplayKey, exp);
128
127
  const rawLevel = identityPayload.lvl;
129
128
  if (rawLevel !== "L0" && rawLevel !== "L1" && rawLevel !== "L2") {
130
129
  throw new Error("unsupported identity level");
@@ -189,10 +188,9 @@ function createRarePlatformKit(config) {
189
188
  );
190
189
  }
191
190
  const replayKey = `action:${session.sessionToken}:${input.nonce}`;
192
- if (await config.replayStore.has(replayKey)) {
191
+ if (!await config.replayStore.claim(replayKey, input.expiresAt)) {
193
192
  throw new Error("action nonce already consumed");
194
193
  }
195
- await config.replayStore.put(replayKey, input.expiresAt);
196
194
  const signingInput = buildActionPayload({
197
195
  aud: config.aud,
198
196
  sessionToken: session.sessionToken,
@@ -254,13 +252,14 @@ var InMemoryChallengeStore = class {
254
252
  };
255
253
  var InMemoryReplayStore = class {
256
254
  seen = /* @__PURE__ */ new Map();
257
- async has(key) {
255
+ async claim(key, expiresAt) {
258
256
  this.cleanup();
259
- return this.seen.has(key);
260
- }
261
- async put(key, expiresAt) {
257
+ if (this.seen.has(key)) {
258
+ return false;
259
+ }
262
260
  this.seen.set(key, expiresAt);
263
261
  this.cleanup();
262
+ return true;
264
263
  }
265
264
  cleanup() {
266
265
  const now = nowTs();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rare-id/platform-kit-web",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,19 +14,19 @@
14
14
  "dist"
15
15
  ],
16
16
  "sideEffects": false,
17
- "license": "MIT",
17
+ "license": "Apache-2.0",
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "git+https://github.com/0xsidfan/Rare.git",
21
- "directory": "rare-platform-kit-ts/packages/platform-kit-web"
20
+ "url": "git+https://github.com/Rare-ID/Rare.git",
21
+ "directory": "packages/platform/ts/rare-platform-kit-ts/packages/platform-kit-web"
22
22
  },
23
23
  "publishConfig": {
24
24
  "access": "public",
25
25
  "provenance": false
26
26
  },
27
27
  "dependencies": {
28
- "@rare-id/platform-kit-client": "0.1.0",
29
- "@rare-id/platform-kit-core": "0.1.0"
28
+ "@rare-id/platform-kit-client": "0.1.1",
29
+ "@rare-id/platform-kit-core": "0.1.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "jose": "^6.0.8",