@pdsjs/spaces 1.0.2 → 2.0.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/package.json +2 -2
- package/src/handlers/auth.js +3 -3
- package/src/handlers/manage.js +1 -1
- package/src/token.js +5 -1
- package/src/verifier.d.ts +1 -15
- package/src/verifier.js +5 -71
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdsjs/spaces",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"./service-auth": "./src/service-auth.js"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@pdsjs/core": "1.0
|
|
26
|
+
"@pdsjs/core": "2.1.0"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
package/src/handlers/auth.js
CHANGED
|
@@ -202,7 +202,7 @@ export function createAuthRoutes(ctx) {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
const spaceRow = await spaceStorage.getSpace(space);
|
|
205
|
-
if (!spaceRow
|
|
205
|
+
if (!spaceRow?.isOwner) {
|
|
206
206
|
return errorResponse('SpaceNotFound', 'Space not found', 404);
|
|
207
207
|
}
|
|
208
208
|
if (spaceRow.deletedAt) {
|
|
@@ -266,7 +266,7 @@ export function createAuthRoutes(ctx) {
|
|
|
266
266
|
const space = url.searchParams.get('space');
|
|
267
267
|
if (!space) return errorResponse('InvalidRequest', 'space is required');
|
|
268
268
|
const row = await spaceStorage.getSpace(space);
|
|
269
|
-
if (!row
|
|
269
|
+
if (!row?.isOwner) {
|
|
270
270
|
return errorResponse('SpaceNotFound', 'Space not found', 404);
|
|
271
271
|
}
|
|
272
272
|
return Response.json({
|
|
@@ -305,7 +305,7 @@ export function createAuthRoutes(ctx) {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
const row = await spaceStorage.getSpace(space);
|
|
308
|
-
if (!row
|
|
308
|
+
if (!row?.isOwner) {
|
|
309
309
|
return errorResponse('SpaceNotFound', 'Space not found', 404);
|
|
310
310
|
}
|
|
311
311
|
|
package/src/handlers/manage.js
CHANGED
package/src/token.js
CHANGED
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
// They share a wire shape and differ only in who signs, who they address, and
|
|
8
8
|
// how long they live — so they are data, not three implementations.
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
base64UrlDecode,
|
|
12
|
+
base64UrlEncode,
|
|
13
|
+
bytesToHex,
|
|
14
|
+
} from '@pdsjs/core/crypto';
|
|
11
15
|
|
|
12
16
|
export const SPACE_TOKEN_TYPES = {
|
|
13
17
|
delegation: {
|
package/src/verifier.d.ts
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @param {string} didKey - did:key:z… (the did: prefix is optional)
|
|
3
|
-
* @returns {{curve: 'p256'|'secp256k1', publicKey: Uint8Array}}
|
|
4
|
-
*/
|
|
5
|
-
export declare function parseDidKey(didKey: string): {
|
|
6
|
-
curve: 'p256' | 'secp256k1';
|
|
7
|
-
publicKey: Uint8Array;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* @param {{secp256k1?: (publicKey: Uint8Array, data: Uint8Array, sig: Uint8Array) => Promise<boolean>}} [opts]
|
|
11
|
-
* @returns {import('@pdsjs/core/ports').SignatureVerifierPort}
|
|
12
|
-
*/
|
|
13
|
-
export declare function createVerifier(opts?: {
|
|
14
|
-
secp256k1?: (publicKey: Uint8Array, data: Uint8Array, sig: Uint8Array) => Promise<boolean>;
|
|
15
|
-
}): import('@pdsjs/core/ports').SignatureVerifierPort;
|
|
1
|
+
export { createVerifier, parseDidKey } from '@pdsjs/core/verify';
|
package/src/verifier.js
CHANGED
|
@@ -1,74 +1,8 @@
|
|
|
1
1
|
// @pdsjs/spaces/verifier - signature verification port.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// The implementation now lives in @pdsjs/core/verify so that core features
|
|
4
|
+
// (service-auth verification on account migration) and spaces (space
|
|
5
|
+
// credentials) share one verifier. This module re-exports it to keep the
|
|
6
|
+
// @pdsjs/spaces/verifier entry point stable for existing importers.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const SECP256K1_MULTICODEC = [0xe7, 0x01];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @param {string} didKey - did:key:z… (the did: prefix is optional)
|
|
14
|
-
* @returns {{curve: 'p256'|'secp256k1', publicKey: Uint8Array}}
|
|
15
|
-
*/
|
|
16
|
-
export function parseDidKey(didKey) {
|
|
17
|
-
const value = didKey.startsWith('did:key:') ? didKey.slice(8) : didKey;
|
|
18
|
-
if (!value.startsWith('z')) {
|
|
19
|
-
throw new Error(`expected a did:key multibase value, got: ${didKey}`);
|
|
20
|
-
}
|
|
21
|
-
const bytes = base58btcDecode(value.slice(1));
|
|
22
|
-
if (bytes[0] === P256_MULTICODEC[0] && bytes[1] === P256_MULTICODEC[1]) {
|
|
23
|
-
return { curve: 'p256', publicKey: bytes.slice(2) };
|
|
24
|
-
}
|
|
25
|
-
if (
|
|
26
|
-
bytes[0] === SECP256K1_MULTICODEC[0] &&
|
|
27
|
-
bytes[1] === SECP256K1_MULTICODEC[1]
|
|
28
|
-
) {
|
|
29
|
-
return { curve: 'secp256k1', publicKey: bytes.slice(2) };
|
|
30
|
-
}
|
|
31
|
-
throw new Error(`unsupported did:key multicodec: ${didKey}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @param {{secp256k1?: (publicKey: Uint8Array, data: Uint8Array, sig: Uint8Array) => Promise<boolean>}} [opts]
|
|
36
|
-
* @returns {import('@pdsjs/core/ports').SignatureVerifierPort}
|
|
37
|
-
*/
|
|
38
|
-
export function createVerifier(opts = {}) {
|
|
39
|
-
return {
|
|
40
|
-
async verify(didKey, data, sig) {
|
|
41
|
-
const { curve, publicKey } = parseDidKey(didKey);
|
|
42
|
-
if (curve === 'p256') return verifyP256(publicKey, data, sig);
|
|
43
|
-
if (!opts.secp256k1) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
'secp256k1 verification requires an injected verifier; ' +
|
|
46
|
-
'this deployment supports P-256 keys only',
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return opts.secp256k1(publicKey, data, sig);
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @param {Uint8Array} publicKey - 33-byte compressed point
|
|
56
|
-
* @param {Uint8Array} data
|
|
57
|
-
* @param {Uint8Array} sig - 64-byte raw r||s
|
|
58
|
-
* @returns {Promise<boolean>}
|
|
59
|
-
*/
|
|
60
|
-
async function verifyP256(publicKey, data, sig) {
|
|
61
|
-
const key = await crypto.subtle.importKey(
|
|
62
|
-
'raw',
|
|
63
|
-
/** @type {BufferSource} */ (publicKey),
|
|
64
|
-
{ name: 'ECDSA', namedCurve: 'P-256' },
|
|
65
|
-
false,
|
|
66
|
-
['verify'],
|
|
67
|
-
);
|
|
68
|
-
return crypto.subtle.verify(
|
|
69
|
-
{ name: 'ECDSA', hash: 'SHA-256' },
|
|
70
|
-
key,
|
|
71
|
-
/** @type {BufferSource} */ (sig),
|
|
72
|
-
/** @type {BufferSource} */ (data),
|
|
73
|
-
);
|
|
74
|
-
}
|
|
8
|
+
export { createVerifier, parseDidKey } from '@pdsjs/core/verify';
|