sos-sdk-node-ts 0.1.0 → 0.1.2
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 +21 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/secure-message-crypto.d.ts +7 -0
- package/dist/secure-message-crypto.js +14 -0
- package/docs/SECURE_MESSAGES.md +32 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
# sos-sdk-node-ts
|
|
2
|
+
## Blocking local-first SDK release
|
|
3
|
+
|
|
4
|
+
The canonical contract is [`SDK_LAYERING.md`](https://github.com/Fundacion-UNID/sos-data-utils-ts/blob/main/docs/SDK_LAYERING.md). Its
|
|
5
|
+
indivisible order is **local packages -> full local test matrix -> merge every
|
|
6
|
+
validated branch to `main` -> publish bottom-up -> install exact registry
|
|
7
|
+
versions and commit lockfiles on `main` -> staging**. Never publish to discover
|
|
8
|
+
deterministic failures and never commit a local package reference. Staging
|
|
9
|
+
begins only after exact registry packages are installed and verified.
|
|
10
|
+
|
|
2
11
|
|
|
3
12
|
SOSChain-specific Node adapters built above the shared runtime-neutral SDK.
|
|
4
13
|
|
|
@@ -22,6 +31,18 @@ emergency request over HTTPS with a stable idempotency key and validates the
|
|
|
22
31
|
provider acknowledgement. The bearer credential remains only in the trusted
|
|
23
32
|
Node runtime.
|
|
24
33
|
|
|
34
|
+
## Secure-message CSPRNG adapter
|
|
35
|
+
|
|
36
|
+
`sos-sdk-node-ts/secure-message-crypto` exports `NodeSecureRandomSource` and
|
|
37
|
+
`createNodeSecureMessageCrypto()`. Node supplies only bytes from
|
|
38
|
+
`node:crypto.randomBytes`; the runtime-neutral `sos-sdk-core-ts` package owns
|
|
39
|
+
ML-KEM, key derivation, recipient CEK wrapping and AES content encryption.
|
|
40
|
+
|
|
41
|
+
The factory handles UTF-8 text and binary audio through the same byte-oriented
|
|
42
|
+
API. Applications select the protected `contentType`, apply their own upload or
|
|
43
|
+
audio-duration limits, and authorize every recipient change before calling the
|
|
44
|
+
shared core. See [docs/SECURE_MESSAGES.md](docs/SECURE_MESSAGES.md).
|
|
45
|
+
|
|
25
46
|
```bash
|
|
26
47
|
npm ci
|
|
27
48
|
npm run check
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MultiRecipientSecureMessageCrypto, type SecureRandomSource } from 'sos-sdk-core-ts/secure-message-crypto';
|
|
2
|
+
/** Node.js CSPRNG adapter. All ML-KEM, KDF and AES operations remain in shared core. */
|
|
3
|
+
export declare class NodeSecureRandomSource implements SecureRandomSource {
|
|
4
|
+
getRandomBytes(length: number): Promise<Uint8Array>;
|
|
5
|
+
}
|
|
6
|
+
/** Create runtime-neutral secure-message crypto with the Node.js CSPRNG boundary. */
|
|
7
|
+
export declare const createNodeSecureMessageCrypto: () => MultiRecipientSecureMessageCrypto;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { MultiRecipientSecureMessageCrypto, } from 'sos-sdk-core-ts/secure-message-crypto';
|
|
3
|
+
const NODE_RANDOM_BYTES_MAX_LENGTH = 2 ** 31 - 1;
|
|
4
|
+
/** Node.js CSPRNG adapter. All ML-KEM, KDF and AES operations remain in shared core. */
|
|
5
|
+
export class NodeSecureRandomSource {
|
|
6
|
+
async getRandomBytes(length) {
|
|
7
|
+
if (!Number.isSafeInteger(length) || length <= 0 || length > NODE_RANDOM_BYTES_MAX_LENGTH) {
|
|
8
|
+
throw new Error('secure_random_length_invalid');
|
|
9
|
+
}
|
|
10
|
+
return new Uint8Array(randomBytes(length));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Create runtime-neutral secure-message crypto with the Node.js CSPRNG boundary. */
|
|
14
|
+
export const createNodeSecureMessageCrypto = () => (new MultiRecipientSecureMessageCrypto(new NodeSecureRandomSource()));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Secure messages in Node.js
|
|
2
|
+
|
|
3
|
+
Use `createNodeSecureMessageCrypto()` from
|
|
4
|
+
`sos-sdk-node-ts/secure-message-crypto`. The factory composes the shared
|
|
5
|
+
runtime-neutral implementation with a Node CSPRNG adapter.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createNodeSecureMessageCrypto } from 'sos-sdk-node-ts/secure-message-crypto';
|
|
9
|
+
|
|
10
|
+
const secureMessages = createNodeSecureMessageCrypto();
|
|
11
|
+
const recipient = await secureMessages.generateRecipientKeyPair(deviceKeyId);
|
|
12
|
+
|
|
13
|
+
const envelope = await secureMessages.seal({
|
|
14
|
+
plaintext: recordedAudioBytes,
|
|
15
|
+
contentType: 'audio/ogg',
|
|
16
|
+
recipients: [recipient],
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Written messages use the same call after UTF-8 encoding, for example with
|
|
21
|
+
`contentType: 'text/plain;charset=utf-8'`. Decrypt the returned bytes only in
|
|
22
|
+
an authorized recipient runtime; decode text or play audio after decryption.
|
|
23
|
+
|
|
24
|
+
`NodeSecureRandomSource` validates the requested size and returns a fresh copy
|
|
25
|
+
of `node:crypto.randomBytes(...)`. It does not own keys or perform any other
|
|
26
|
+
cryptographic operation. Never replace it with `Math.random`, timestamps,
|
|
27
|
+
identifiers or deterministic application data.
|
|
28
|
+
|
|
29
|
+
Recipient lifecycle and authorization remain separate. A service may rewrap a
|
|
30
|
+
CEK to current device/channel keys and remove its temporary recipient entry,
|
|
31
|
+
but only after the product has authorized that change. The storage service
|
|
32
|
+
persists the opaque envelope and does not need plaintext access.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sos-sdk-node-ts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "SOSChain-specific Node adapters over the shared runtime-neutral SOS SDK",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Connecting Solution & Applications Ltd",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"./emergency-dispatch": {
|
|
20
20
|
"types": "./dist/emergency-dispatch.d.ts",
|
|
21
21
|
"default": "./dist/emergency-dispatch.js"
|
|
22
|
+
},
|
|
23
|
+
"./secure-message-crypto": {
|
|
24
|
+
"types": "./dist/secure-message-crypto.d.ts",
|
|
25
|
+
"default": "./dist/secure-message-crypto.js"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
"files": [
|
|
@@ -35,7 +39,7 @@
|
|
|
35
39
|
"prepack": "npm run check"
|
|
36
40
|
},
|
|
37
41
|
"dependencies": {
|
|
38
|
-
"sos-sdk-core-ts": "0.2.
|
|
42
|
+
"sos-sdk-core-ts": "0.2.2"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
45
|
"@types/node": "^24.10.0",
|