organic-protocol 0.1.1 → 0.2.0
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/PROTOCOL.md +9 -5
- package/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/wire.d.ts +14 -4
- package/dist/wire.js +5 -5
- package/package.json +9 -1
package/PROTOCOL.md
CHANGED
|
@@ -22,7 +22,7 @@ The `url` is the server's **root** URL (no `/api`, no trailing slash), normalize
|
|
|
22
22
|
|
|
23
23
|
```json
|
|
24
24
|
{ "v": 1, "d": 20260719, "t": 3, "p": "<target pk>", "s": "<signer pk>",
|
|
25
|
-
"m":
|
|
25
|
+
"m": "BLeiCZk=", "i": "", "h": "<DER signature, hex>" }
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
| Field | Long name | Content |
|
|
@@ -32,18 +32,22 @@ The `url` is the server's **root** URL (no `/api`, no trailing slash), normalize
|
|
|
32
32
|
| `t` | type | transaction type (§3) |
|
|
33
33
|
| `p` | target | recipient's public key |
|
|
34
34
|
| `s` | signer | sender's public key |
|
|
35
|
-
| `m` | money | money unit ids (
|
|
36
|
-
| `i` | invests | invest unit ids (
|
|
35
|
+
| `m` | money | packed money unit ids (§2.3) |
|
|
36
|
+
| `i` | invests | packed invest unit ids (§2.3) |
|
|
37
37
|
| `h` | signature | SECP256K1 DER signature, hex |
|
|
38
38
|
|
|
39
39
|
### 2.2 Block (`BlockWire`)
|
|
40
40
|
|
|
41
41
|
```json
|
|
42
42
|
{ "v": 1, "d": 20260719, "p": "<previous block signature>", "s": "<pk>",
|
|
43
|
-
"m":
|
|
43
|
+
"m": "", "i": "", "t": 42, "r": "<merkle root>", "h": "<signature>", "x": [ …TxWire ] }
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
Here `t` is the **total** (cumulative economic experience); `p` is the previous block's signature (chain link); `x` is the transaction list.
|
|
46
|
+
Here `t` is the **total** (cumulative economic experience); `p` is the previous block's signature (chain link); `x` is the transaction list. `m`/`i` are the available (unspent) money/invest ids at seal time, packed the same way as in a transaction (§2.3).
|
|
47
|
+
|
|
48
|
+
### 2.3 Packed unit ids (`m`, `i`)
|
|
49
|
+
|
|
50
|
+
Money and invest unit ids (`YYYYMMDDXXX` / `YYYYMMDD9XXX`, §2.1 table) are **not** a JSON array of numbers on the wire — a plain decimal array costs 12 bytes per id (11-12 digits plus a separator) for ~5 bytes of actual information, which matters once a paper bill (§4, `PP`) bundles many ids into one QR code. Instead: each id is packed into 5 big-endian bytes (comfortably covers every possible id), all ids are concatenated, and the result is base64-encoded into a single string. An empty array is the empty string `""`. Order and duplicates are preserved. Reference implementation: `packUnitIds`/`unpackUnitIds` in [`organic-money`](https://www.npmjs.com/package/organic-money) (`src/crypto.js`); `organic-protocol` validates the shape (`isTxWire`/`isBlockWire`) but does not implement the packing itself.
|
|
47
51
|
|
|
48
52
|
## 3. Transaction types
|
|
49
53
|
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
This package carries the **shapes** that travel between Organic Economy instances: transaction and block wire formats, the versioned QR standard (`OM1:CT/TX/BR/PP`) with its encode/decode functions, and the DTOs of the `/api/v1` REST contract. It contains **no cryptography** — that lives in [`organic-money`](https://www.npmjs.com/package/organic-money).
|
|
6
6
|
|
|
7
|
-
The [organic-webapp](https://github.com/
|
|
7
|
+
The [organic-webapp](https://github.com/OrganicEconomy/organic-webapp) client and the [organic-webserver](https://github.com/OrganicEconomy/organic-webserver) server both import this package, so any drift between what one sends and the other expects becomes a compile error instead of a silent bug. Third-party implementations should either import it or implement [PROTOCOL.md](PROTOCOL.md), which is the same standard in prose.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm install organic-protocol
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { PROTOCOL_VERSION, TxType, isTxWire, isBlockWire, type IntDate, type UnitId, type PublicKeyHex, type SignatureHex, type TxWire, type BlockWire, } from './wire.js';
|
|
1
|
+
export { PROTOCOL_VERSION, TxType, isTxWire, isBlockWire, type IntDate, type UnitId, type PackedUnitIds, type PublicKeyHex, type SignatureHex, type TxWire, type BlockWire, } from './wire.js';
|
|
2
2
|
export { InvalidServerUrlError, normalizeServerUrl, type Identity, type Contact, type ContactType, } from './identity.js';
|
|
3
3
|
export { QR_VERSION, QrError, UnsupportedQrVersionError, InvalidQrError, encodeContactQr, encodeOfflineTxQr, encodeValidationQr, encodePaperQr, decodeQr, type QrType, type DecodedQr, type ContactQrPayload, type OfflineTxQrPayload, type ValidationQrPayload, type PaperQrPayload, } from './qr.js';
|
|
4
4
|
export type { ApiError, ApiErrorCode, InfoResponse, ServerListEntry, ServersResponse, RegisterBody, RegisterResponse, LoginBody, LoginResponse, SaveBlockBody, SignBlockBody, PasswordChangeBody, TxSendBody, TxListResponse, TxVerifyBody, TxVerifyStatus, TxVerifyResponse, PapersCashBody, IsCashedResponse, } from './api.js';
|
package/dist/wire.d.ts
CHANGED
|
@@ -29,6 +29,16 @@ export type IntDate = number;
|
|
|
29
29
|
* The creation date is embedded in the id.
|
|
30
30
|
*/
|
|
31
31
|
export type UnitId = number;
|
|
32
|
+
/**
|
|
33
|
+
* Wire representation of a `UnitId[]`: each id packed into 5 big-endian
|
|
34
|
+
* bytes (comfortably covers every possible money/invest id), concatenated,
|
|
35
|
+
* then base64-encoded. An empty array is the empty string. A plain JSON
|
|
36
|
+
* number array costs 12 bytes per id (11-12 decimal digits + a separator)
|
|
37
|
+
* for ~5 bytes of actual information — this roughly halves the size of a
|
|
38
|
+
* transaction or block on the wire, which matters most for QR-encoded
|
|
39
|
+
* paper bills. Mirrors `packUnitIds`/`unpackUnitIds` in organic-money.
|
|
40
|
+
*/
|
|
41
|
+
export type PackedUnitIds = string;
|
|
32
42
|
/** Compressed SECP256K1 public key, hex-encoded (33 bytes → 66 chars). */
|
|
33
43
|
export type PublicKeyHex = string;
|
|
34
44
|
/** DER-encoded SECP256K1 signature, hex-encoded. */
|
|
@@ -44,8 +54,8 @@ export interface TxWire {
|
|
|
44
54
|
t: TxType;
|
|
45
55
|
p: PublicKeyHex;
|
|
46
56
|
s: PublicKeyHex;
|
|
47
|
-
m:
|
|
48
|
-
i:
|
|
57
|
+
m: PackedUnitIds;
|
|
58
|
+
i: PackedUnitIds;
|
|
49
59
|
h: SignatureHex;
|
|
50
60
|
}
|
|
51
61
|
/**
|
|
@@ -60,8 +70,8 @@ export interface BlockWire {
|
|
|
60
70
|
d: IntDate;
|
|
61
71
|
p: string;
|
|
62
72
|
s: PublicKeyHex;
|
|
63
|
-
m:
|
|
64
|
-
i:
|
|
73
|
+
m: PackedUnitIds;
|
|
74
|
+
i: PackedUnitIds;
|
|
65
75
|
t: number;
|
|
66
76
|
r: string;
|
|
67
77
|
h: SignatureHex;
|
package/dist/wire.js
CHANGED
|
@@ -23,7 +23,7 @@ export var TxType;
|
|
|
23
23
|
TxType[TxType["EARN"] = 13] = "EARN";
|
|
24
24
|
})(TxType || (TxType = {}));
|
|
25
25
|
const isHex = (s) => typeof s === 'string' && /^[0-9a-fA-F]*$/.test(s);
|
|
26
|
-
const
|
|
26
|
+
const isPackedUnitIds = (s) => typeof s === 'string' && /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(s);
|
|
27
27
|
/** Structural check that an unknown value is a well-formed TxWire. */
|
|
28
28
|
export function isTxWire(o) {
|
|
29
29
|
if (typeof o !== 'object' || o === null)
|
|
@@ -37,8 +37,8 @@ export function isTxWire(o) {
|
|
|
37
37
|
t.t <= TxType.EARN &&
|
|
38
38
|
isHex(t.p) &&
|
|
39
39
|
isHex(t.s) &&
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
isPackedUnitIds(t.m) &&
|
|
41
|
+
isPackedUnitIds(t.i) &&
|
|
42
42
|
isHex(t.h));
|
|
43
43
|
}
|
|
44
44
|
/** Structural check that an unknown value is a well-formed BlockWire. */
|
|
@@ -50,8 +50,8 @@ export function isBlockWire(o) {
|
|
|
50
50
|
typeof b.d === 'number' &&
|
|
51
51
|
isHex(b.p) &&
|
|
52
52
|
isHex(b.s) &&
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
isPackedUnitIds(b.m) &&
|
|
54
|
+
isPackedUnitIds(b.i) &&
|
|
55
55
|
typeof b.t === 'number' &&
|
|
56
56
|
isHex(b.r) &&
|
|
57
57
|
isHex(b.h) &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "organic-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The shared protocol of the Organic Economy: wire formats, QR codes and API contracts, verified by the TypeScript compiler. Companion of organic-money.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"organic-economy",
|
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"author": "suipotryot",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/OrganicEconomy/organic-protocol.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/OrganicEconomy/organic-protocol/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/OrganicEconomy/organic-protocol#readme",
|
|
13
21
|
"type": "module",
|
|
14
22
|
"main": "./dist/index.js",
|
|
15
23
|
"types": "./dist/index.d.ts",
|