@pamoja/security 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 +79 -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,79 @@
|
|
|
1
|
+
# @pamoja/security
|
|
2
|
+
|
|
3
|
+
ed25519 device identity: sign a reading and verify it, so a gateway can prove it is authentic. 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_security.html)
|
|
6
|
+
[](https://pamoja.molex.cloud/docs/guides/security.html)
|
|
7
|
+
[](https://pamoja.molex.cloud/docs/)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @pamoja/security
|
|
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/security.ts`](https://github.com/molexxxx/pamoja/blob/main/bindings/node/guides/security.ts):
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { DeviceIdentity, fingerprint, verify } from '@pamoja/security'
|
|
25
|
+
|
|
26
|
+
// The seed is provisioned into the device once and never leaves it. A real one comes from
|
|
27
|
+
// the factory or a secure element; any 32 bytes stand in here.
|
|
28
|
+
const device = DeviceIdentity.fromSeed(Buffer.alloc(32, 7))
|
|
29
|
+
|
|
30
|
+
// Only the 32-byte public key travels to the gateway. Its fingerprint is the short form an
|
|
31
|
+
// operator reads off a screen to tell one device from another.
|
|
32
|
+
const gatewayKey = device.publicKey()
|
|
33
|
+
console.log(`device ${fingerprint(gatewayKey)}`)
|
|
34
|
+
|
|
35
|
+
// Signing is deterministic, so the same reading always produces the same 64 bytes and there
|
|
36
|
+
// is no randomness to get wrong on a microcontroller.
|
|
37
|
+
const reading = 'meter-4 1182.750 kWh'
|
|
38
|
+
const signature = device.sign(reading)
|
|
39
|
+
if (verify(gatewayKey, reading, signature)) {
|
|
40
|
+
console.log(`accepted ${reading}`)
|
|
41
|
+
} else {
|
|
42
|
+
console.log('rejected a reading the device really did sign, which should never happen')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// A digit changed in transit no longer matches what was signed.
|
|
46
|
+
const edited = 'meter-4 1082.750 kWh'
|
|
47
|
+
if (verify(gatewayKey, edited, signature)) {
|
|
48
|
+
console.log('accepted an edited reading, which should never happen')
|
|
49
|
+
} else {
|
|
50
|
+
console.log(`rejected ${edited}`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Nor does the same reading offered under another device's key.
|
|
54
|
+
const impostor = DeviceIdentity.fromSeed(Buffer.alloc(32, 90))
|
|
55
|
+
if (verify(impostor.publicKey(), reading, signature)) {
|
|
56
|
+
console.log('accepted an impostor, which should never happen')
|
|
57
|
+
} else {
|
|
58
|
+
console.log("rejected a signature offered under another device's key")
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## The same capability in every language
|
|
63
|
+
|
|
64
|
+
| Language | Package | Reference |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| Rust | [`pamoja-security`](https://crates.io/crates/pamoja-security) | [reference](https://pamoja.molex.cloud/docs/reference/rust/pamoja_security/index.html), [docs.rs](https://docs.rs/pamoja-security) |
|
|
67
|
+
| TypeScript | [`@pamoja/security`](https://www.npmjs.com/package/@pamoja/security) | [reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_security.html) |
|
|
68
|
+
| Python | [`pamoja-security`](https://pypi.org/project/pamoja-security/) | [reference](https://pamoja.molex.cloud/docs/reference/python/pamoja/security.html) |
|
|
69
|
+
| C# | [`Pamoja.Security`](https://www.nuget.org/packages/Pamoja.Security) | [reference](https://pamoja.molex.cloud/docs/reference/dotnet/api/Pamoja.Security.html) |
|
|
70
|
+
|
|
71
|
+
## Documentation
|
|
72
|
+
|
|
73
|
+
- [`@pamoja/security` reference](https://pamoja.molex.cloud/docs/reference/node/modules/_pamoja_security.html), every class, function, and type this package exports.
|
|
74
|
+
- [The Device identity guide](https://pamoja.molex.cloud/docs/guides/security.html), with the same example in Rust, Python, and C#.
|
|
75
|
+
- [Every capability](https://pamoja.molex.cloud/docs/), and the [install page](https://pamoja.molex.cloud/docs/install.html).
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pamoja/security",
|
|
3
|
+
"version": "0.1.15",
|
|
4
|
+
"description": "ed25519 device identity: sign a reading and verify it, so a gateway can prove it is authentic.",
|
|
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/security"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://pamoja.molex.cloud/docs/guides/security.html",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"pamoja",
|
|
17
|
+
"iot",
|
|
18
|
+
"robotics",
|
|
19
|
+
"security"
|
|
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
|
+
}
|