@pamoja/session 0.1.15
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/LICENSE-MIT +21 -0
- package/README.md +76 -0
- package/package.json +39 -0
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anthony Wiedman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @pamoja/session
|
|
2
|
+
|
|
3
|
+
X25519 key agreement, HKDF, and ChaCha20-Poly1305 with an anti-replay window, with no TLS stack. One capability of [pamoja](https://github.com/molexxxx/pamoja), one memory-safe Rust core with bindings for TypeScript, Python, and C#.
|
|
4
|
+
|
|
5
|
+
[](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_session.html)
|
|
6
|
+
[](https://pamoja.molex.cloud/docs/guides/session.html)
|
|
7
|
+
[](https://pamoja.molex.cloud/docs/)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @pamoja/session
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This pulls in `@pamoja/native`, the compiled engine. `npm install pamoja` is the whole framework in one package.
|
|
16
|
+
|
|
17
|
+
## Example
|
|
18
|
+
|
|
19
|
+
The test that runs in CI, spliced here as it ran.
|
|
20
|
+
|
|
21
|
+
From [`bindings/node/guides/session.ts`](https://github.com/molexxxx/pamoja/blob/main/bindings/node/guides/session.ts):
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { AgreementKey, Role, Session } from '@pamoja/session'
|
|
25
|
+
|
|
26
|
+
// Each device is provisioned with a 32-byte seed and publishes the key it derives. A real
|
|
27
|
+
// seed comes from the factory or a secure element; any 32 bytes stand in here.
|
|
28
|
+
const node = new AgreementKey(Buffer.alloc(32, 7))
|
|
29
|
+
const gateway = new AgreementKey(Buffer.alloc(32, 9))
|
|
30
|
+
|
|
31
|
+
// Neither side sends the session key. Both derive it from the shared secret, a salt that
|
|
32
|
+
// travels in the clear, and both public keys, with opposite roles.
|
|
33
|
+
//
|
|
34
|
+
// The salt must be fresh for every session: reusing one derives the same key from the same
|
|
35
|
+
// pair of devices twice. The initiator draws it and sends it in the clear, so the responder
|
|
36
|
+
// uses the salt it received rather than one of its own.
|
|
37
|
+
const salt = randomBytes(16)
|
|
38
|
+
const uplink = new Session(node, gateway.publicKey(), salt, Role.Initiator)
|
|
39
|
+
const downlink = new Session(gateway, node.publicKey(), salt, Role.Responder)
|
|
40
|
+
console.log('both sides derived a key without sending one')
|
|
41
|
+
|
|
42
|
+
// The pump id is authenticated but not encrypted, so a router still reads it while any
|
|
43
|
+
// change to it fails the tag.
|
|
44
|
+
const reading = Buffer.from('flow=41.2')
|
|
45
|
+
const sealed = uplink.seal(reading, Buffer.from('pump-3'))
|
|
46
|
+
console.log(`sealed the reading is no longer readable: ${!sealed.ciphertext.equals(reading)}`)
|
|
47
|
+
console.log(`opened ${downlink.open(sealed, Buffer.from('pump-3')).toString()}`)
|
|
48
|
+
|
|
49
|
+
// The anti-replay window refuses a counter it has already accepted, so a frame captured
|
|
50
|
+
// off the air and sent again is not delivered a second time.
|
|
51
|
+
try {
|
|
52
|
+
downlink.open(sealed, Buffer.from('pump-3'))
|
|
53
|
+
console.log('a replayed frame was accepted, which should never happen')
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.log(`replay refused: ${(error as Error).message}`)
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## The same capability in every language
|
|
60
|
+
|
|
61
|
+
| Language | Package | Reference |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| Rust | [`pamoja-session`](https://crates.io/crates/pamoja-session) | [reference](https://pamoja.molex.cloud/docs/reference/rust/pamoja_session/index.html), [docs.rs](https://docs.rs/pamoja-session) |
|
|
64
|
+
| TypeScript | [`@pamoja/session`](https://www.npmjs.com/package/@pamoja/session) | [reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_session.html) |
|
|
65
|
+
| Python | [`pamoja-session`](https://pypi.org/project/pamoja-session/) | [reference](https://pamoja.molex.cloud/docs/reference/python/pamoja/session.html) |
|
|
66
|
+
| C# | [`Pamoja.Session`](https://www.nuget.org/packages/Pamoja.Session) | [reference](https://pamoja.molex.cloud/docs/reference/dotnet/api/Pamoja.Session.html) |
|
|
67
|
+
|
|
68
|
+
## Documentation
|
|
69
|
+
|
|
70
|
+
- [`@pamoja/session` reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_session.html), every class, function, and type this package exports.
|
|
71
|
+
- [The Secured session guide](https://pamoja.molex.cloud/docs/guides/session.html), with the same example in Rust, Python, and C#.
|
|
72
|
+
- [Every capability](https://pamoja.molex.cloud/docs/), and the [install page](https://pamoja.molex.cloud/docs/install.html).
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pamoja/session",
|
|
3
|
+
"version": "0.1.15",
|
|
4
|
+
"description": "X25519 key agreement, HKDF, and ChaCha20-Poly1305 with an anti-replay window, with no TLS stack.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/molexxxx/pamoja.git",
|
|
12
|
+
"directory": "bindings/node/packages/session"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://pamoja.molex.cloud/docs/guides/session.html",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"pamoja",
|
|
17
|
+
"iot",
|
|
18
|
+
"robotics",
|
|
19
|
+
"session"
|
|
20
|
+
],
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/",
|
|
31
|
+
"LICENSE-MIT"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">= 16"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@pamoja/native": "0.1.15"
|
|
38
|
+
}
|
|
39
|
+
}
|