@greenlandai/sdk 0.5.16 → 3.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/CHANGELOG.md +28 -0
- package/README.md +12 -0
- package/dist/index.cjs +108 -19
- package/index.js +1 -1
- package/package.json +10 -1
- package/src/core/crypto.js +42 -3
- package/src/core/messaging_client.js +304 -0
- package/src/core/messaging_store_node.js +94 -0
- package/src/core/messaging_v4.js +532 -0
- package/src/enyal.js +30 -5
- package/src/gldai.js +16 -5
- package/src/joulepai.js +14 -1
- package/src/rareeai.js +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## 3.0.1 (2026-10-18)
|
|
2
|
+
The first published release since 0.5.17: it carries everything listed below under "Unreleased" (the messaging v4 client of
|
|
3
|
+
3.0.0, which was signed but never published), plus:
|
|
4
|
+
- **JoulePAI wallet routes follow the owner-route rule.** `client.joulepai.setHandle` and `setLimits` are SESSION-ONLY, like
|
|
5
|
+
`contributeEnable`: build the Client with your signed-in session (`oauthToken`: the ENYAL session from sign-in, or joulepai.ai's
|
|
6
|
+
own session JWT). An API key or OAuth token gets 403 `session_required` (ScopeError, the reason in `detail`). `createWallet` takes
|
|
7
|
+
a signed-in session, or an agent key its owner granted the custom scope `wallet:create`; otherwise 403 `scope_not_granted`.
|
|
8
|
+
Routes and request bodies are unchanged; `getLimits` is unchanged.
|
|
9
|
+
- `rareeai.createRequest` accepts `provider_id` (the request matches that listing only).
|
|
10
|
+
- `joulepai.resetCredentials` now documents that no key is sent and nothing is rotated — the wallet's email is told how to get a
|
|
11
|
+
new key (signed in, Dashboard → API Credentials, POST /wallet/regenerate-key).
|
|
12
|
+
|
|
13
|
+
## Unreleased (P-DAY.131, messaging branch) — released in 3.0.1
|
|
14
|
+
- **The "got it" receipt.** Since 2026-10-10 ENYAL's inbox and thread reads write nothing; `delivered_at` (the sender's
|
|
15
|
+
Delivered) is set only by `POST /api/v1/message/ack`. `client.enyal.getInbox` / `getThread` now send it for the messages they
|
|
16
|
+
return that are not yet delivered (the server marks only yours, never as read); the result carries `acked` or `ack_error`
|
|
17
|
+
(the read stands; the next read retries); `ack: false` skips it. New `client.enyal.ackMessages(ids)`.
|
|
18
|
+
|
|
19
|
+
## 0.5.17 (2026-10-04)
|
|
20
|
+
- **`decrypt_message` / `crypto.decryptMessage` refuse what they cannot open instead of mis-reading it.** A crypto_version 1
|
|
21
|
+
message (sent before 2026-08-16, encrypted to the platform), a blob version other than v5 / v6, a blob shorter than its format
|
|
22
|
+
or a non-base64 payload now raise `MessageFormatError` with a `code` (legacy_message, unknown_version, truncated,
|
|
23
|
+
bad_encoding, missing_payload) — the format is checked before any key work. Until now an unknown or short blob was parsed
|
|
24
|
+
anyway and failed later as a generic decryption error, and a legacy message was attempted. A wrong share or a tampered
|
|
25
|
+
message still fails the AES-GCM check. The helper is now in the interop KAT (checks xi–xviii, against blobs the ENYAL server
|
|
26
|
+
encrypted); it had no test before. Same codes as enyal-sdk / @enyalai/sdk 2.2.14.
|
|
27
|
+
- Docstrings: "developer key" wording removed (personal gai_ keys are retired).
|
|
28
|
+
|
|
1
29
|
## 0.5.16 (2026-10-03)
|
|
2
30
|
- **A missing path id is refused before any request** (all 29 methods that put an id in the URL path: ENYAL lineage / thread /
|
|
3
31
|
knowledge nodes, GreenlandAI company / deposit / infrastructure / project, RAREEAI match actions, JoulePAI wallet / transfer /
|
package/README.md
CHANGED
|
@@ -9,6 +9,16 @@ published and maintained — use that one if you only need ENYAL.
|
|
|
9
9
|
npm install @greenlandai/sdk
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
## Agent keys
|
|
13
|
+
|
|
14
|
+
An agent_ key (JoulePAI) is registered by its owner: `POST https://joulepai.ai/api/v1/agents/register` with the owner's jlp_ key or
|
|
15
|
+
session, body `{"name": "<name>", "access": "full_agent", "daily_spend_limit": 0}`. `access` is `full_agent`, `read_only` or `custom` (with
|
|
16
|
+
`scopes`). Without `access` the key can do nothing (every call is refused, 403 `agent_not_allowed`) until the owner grants it with
|
|
17
|
+
`PUT /api/v1/agents/{agent_id}/access`; the register reply's `next_step` says so. The key is shown once; `GET /api/v1/agents` reads back each
|
|
18
|
+
key's access and hint. On the marketplace an agent key needs `marketplace:read` for GET calls and `marketplace:write` for the rest; a
|
|
19
|
+
buyer's escrow lock needs no `wallet:transfer`. An agent_ key works on joulepai.ai/api/v1 and on the marketplace at both doors.
|
|
20
|
+
Full detail: https://joulepai.ai/llms.txt.
|
|
21
|
+
|
|
12
22
|
## Auth
|
|
13
23
|
```js
|
|
14
24
|
import { Client } from "@greenlandai/sdk"; // ESM
|
|
@@ -32,6 +42,8 @@ const client = new Client({ oauthToken: jwt }); // an OAuth JWT — bare, o
|
|
|
32
42
|
// agentId must be your own: an id another account has used is refused (403), and web-console / web-app /
|
|
33
43
|
// share-extension are reserved for the account owner's apps. Your wallet id (client.enyal.getAccount()).wallet_id
|
|
34
44
|
// is always yours. Messages are addressed by the recipient's JoulePAI wallet id.
|
|
45
|
+
// Reading the inbox/thread then sends the "got it" receipt (POST /message/ack) so senders see Delivered —
|
|
46
|
+
// a read alone sets nothing; ack: false skips it, client.enyal.ackMessages(ids) sends it yourself.
|
|
35
47
|
await client.enyal.archive({ agentId: "<your-own-agent-id>", chunkType: "decision_record", chunkKey: "k1", data: { decision: "x" } });
|
|
36
48
|
await client.joulepai.transfer("@bob", 1000, { note: "thanks" }); // auto idempotency key
|
|
37
49
|
await client.rareeai.createRequest({ resourceType: "gpu" }); // marketplace (flat 1%, floor 50 J — parse fee_joules)
|
package/dist/index.cjs
CHANGED
|
@@ -397,6 +397,8 @@ var Transport = class {
|
|
|
397
397
|
var crypto_exports = {};
|
|
398
398
|
__export(crypto_exports, {
|
|
399
399
|
HASH_SCHEME_COMMIT_V1: () => HASH_SCHEME_COMMIT_V1,
|
|
400
|
+
MESSAGE_BLOB_VERSIONS: () => MESSAGE_BLOB_VERSIONS,
|
|
401
|
+
MessageFormatError: () => MessageFormatError,
|
|
400
402
|
RecordIntegrityError: () => RecordIntegrityError,
|
|
401
403
|
ZK_ENVELOPE_MAGIC: () => ZK_ENVELOPE_MAGIC,
|
|
402
404
|
ZK_ENVELOPE_R_LEN: () => ZK_ENVELOPE_R_LEN,
|
|
@@ -3842,9 +3844,32 @@ function _bytesToBase64(u8) {
|
|
|
3842
3844
|
for (let i = 0; i < u8.length; i++) s += String.fromCharCode(u8[i]);
|
|
3843
3845
|
return btoa(s);
|
|
3844
3846
|
}
|
|
3847
|
+
var MessageFormatError = class extends Error {
|
|
3848
|
+
constructor(code, message) {
|
|
3849
|
+
super(message);
|
|
3850
|
+
this.name = "MessageFormatError";
|
|
3851
|
+
this.code = code;
|
|
3852
|
+
}
|
|
3853
|
+
};
|
|
3854
|
+
var MESSAGE_BLOB_VERSIONS = [5, 6];
|
|
3845
3855
|
function _messageBlobToChunk(payloadBase64) {
|
|
3846
|
-
const
|
|
3856
|
+
const s = String(payloadBase64);
|
|
3857
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(s) || s.length % 4 !== 0) {
|
|
3858
|
+
throw new MessageFormatError("bad_encoding", "encrypted_payload is not valid base64");
|
|
3859
|
+
}
|
|
3860
|
+
const blob = base64ToBytes(s);
|
|
3861
|
+
if (blob.length < 2) throw new MessageFormatError("truncated", `message blob is ${blob.length} bytes \u2014 too short to carry a version`);
|
|
3847
3862
|
const version = blob[0] << 8 | blob[1];
|
|
3863
|
+
if (!MESSAGE_BLOB_VERSIONS.includes(version)) {
|
|
3864
|
+
throw new MessageFormatError(
|
|
3865
|
+
"unknown_version",
|
|
3866
|
+
`message blob version 0x${version.toString(16).padStart(4, "0")} is not one this SDK opens \u2014 upgrade the SDK`
|
|
3867
|
+
);
|
|
3868
|
+
}
|
|
3869
|
+
const fixed = 2 + _MSG_EPHEM_LEN + (version === 6 ? _MSG_MLKEM_LEN : 0) + _MSG_NONCE_LEN + _MSG_TAG_LEN;
|
|
3870
|
+
if (blob.length <= fixed) {
|
|
3871
|
+
throw new MessageFormatError("truncated", `v${version} message blob is ${blob.length} bytes; it needs more than ${fixed}`);
|
|
3872
|
+
}
|
|
3848
3873
|
let off = 2;
|
|
3849
3874
|
const ephem = blob.slice(off, off + _MSG_EPHEM_LEN);
|
|
3850
3875
|
off += _MSG_EPHEM_LEN;
|
|
@@ -3877,7 +3902,13 @@ function mnemonicToCustomerShare(mnemonic) {
|
|
|
3877
3902
|
return share;
|
|
3878
3903
|
}
|
|
3879
3904
|
async function decryptMessage({ message, wrapped, customerShare, recoveryPhrase, p256ScalarMul }) {
|
|
3880
|
-
if (!message || !message.encrypted_payload) throw new
|
|
3905
|
+
if (!message || !message.encrypted_payload) throw new MessageFormatError("missing_payload", "message.encrypted_payload required");
|
|
3906
|
+
if (message.crypto_version === 1) {
|
|
3907
|
+
throw new MessageFormatError("legacy_message", "this message (crypto_version 1, sent before 2026-08-16) was encrypted to the platform, not to your keys \u2014 it cannot be opened here");
|
|
3908
|
+
}
|
|
3909
|
+
if (message.crypto_version === 4 || /^(eyJ|\{)/.test(String(message.encrypted_payload))) {
|
|
3910
|
+
throw new MessageFormatError("messaging_upgrade_required", "this message is end-to-end encrypted (messaging v4) and this SDK cannot open it \u2014 upgrade to @greenlandai/sdk 1.0.0 or later");
|
|
3911
|
+
}
|
|
3881
3912
|
if (!wrapped) throw new ValidationError(null, "wrapped custodial share required (GET /message/my-keys)");
|
|
3882
3913
|
let share;
|
|
3883
3914
|
if (customerShare) {
|
|
@@ -3887,8 +3918,8 @@ async function decryptMessage({ message, wrapped, customerShare, recoveryPhrase,
|
|
|
3887
3918
|
} else {
|
|
3888
3919
|
throw new ValidationError(null, "provide customerShare or recoveryPhrase");
|
|
3889
3920
|
}
|
|
3890
|
-
const custodial = await decryptCustodialShare(share, wrapped);
|
|
3891
3921
|
const chunk = _messageBlobToChunk(message.encrypted_payload);
|
|
3922
|
+
const custodial = await decryptCustodialShare(share, wrapped);
|
|
3892
3923
|
const pt = await decryptDisclosedChunk(share, custodial, chunk, p256ScalarMul);
|
|
3893
3924
|
return new TextDecoder().decode(pt);
|
|
3894
3925
|
}
|
|
@@ -4017,22 +4048,49 @@ var EnyalSubmodule = class {
|
|
|
4017
4048
|
);
|
|
4018
4049
|
}
|
|
4019
4050
|
/** Read your inbox with your OWN JoulePAI wallet id as agentId (or a label your account holds) — messages are
|
|
4020
|
-
* addressed to wallet ids; an id another account holds gets 403.
|
|
4021
|
-
|
|
4022
|
-
|
|
4051
|
+
* addressed to wallet ids; an id another account holds gets 403. Received messages are then acknowledged
|
|
4052
|
+
* (ackMessages) so their senders see Delivered; ack: false reads without acknowledging. The result carries
|
|
4053
|
+
* acked (newly marked) or ack_error. */
|
|
4054
|
+
async getInbox({ agentId, direction = "inbox", ack = true, ...params } = {}) {
|
|
4055
|
+
const res = await this._t.request(
|
|
4023
4056
|
this._base,
|
|
4024
4057
|
"GET",
|
|
4025
4058
|
"/api/v1/message/inbox",
|
|
4026
4059
|
{ params: { agent_id: agentId, direction, ...params } }
|
|
4027
4060
|
);
|
|
4061
|
+
return ack && direction !== "outbox" ? this._ackAfterRead(res) : res;
|
|
4028
4062
|
}
|
|
4029
|
-
|
|
4030
|
-
|
|
4063
|
+
/** The messages of a thread; the ones addressed to you are then acknowledged (see getInbox; ack: false skips it). */
|
|
4064
|
+
async getThread(threadId, { copy, ack = true } = {}) {
|
|
4065
|
+
const res = await this._t.request(
|
|
4031
4066
|
this._base,
|
|
4032
4067
|
"GET",
|
|
4033
4068
|
"/api/v1/message/thread/{thread_id}",
|
|
4034
4069
|
{ pathParams: { thread_id: threadId }, params: copy ? { copy } : {} }
|
|
4035
4070
|
);
|
|
4071
|
+
return ack ? this._ackAfterRead(res) : res;
|
|
4072
|
+
}
|
|
4073
|
+
/** The "got it" receipt: POST /api/v1/message/ack sets delivered_at (the sender's Delivered) on the messages addressed
|
|
4074
|
+
* to you; reading the inbox does not (since 2026-10-10 a read writes nothing). Never marks them read. Free; safe to repeat. */
|
|
4075
|
+
ackMessages(messageIds, retry = true) {
|
|
4076
|
+
return this._t.request(
|
|
4077
|
+
this._base,
|
|
4078
|
+
"POST",
|
|
4079
|
+
"/api/v1/message/ack",
|
|
4080
|
+
{ body: { message_ids: messageIds }, retry }
|
|
4081
|
+
);
|
|
4082
|
+
}
|
|
4083
|
+
// P-DAY.131 (operator: "all 4 SDK packages call POST /message/ack"): ack the read messages not yet delivered. The server
|
|
4084
|
+
// marks only the caller's own received rows. A failed ack never loses the read: ack_error is set and the next read retries.
|
|
4085
|
+
async _ackAfterRead(res) {
|
|
4086
|
+
const ids = (res && res.messages || []).filter((m) => m && m.message_id && !m.delivered_at).map((m) => m.message_id);
|
|
4087
|
+
if (!ids.length) return res;
|
|
4088
|
+
try {
|
|
4089
|
+
res.acked = (await this.ackMessages(ids)).updated;
|
|
4090
|
+
} catch (e) {
|
|
4091
|
+
res.ack_error = e && e.message || String(e);
|
|
4092
|
+
}
|
|
4093
|
+
return res;
|
|
4036
4094
|
}
|
|
4037
4095
|
/** P-DAY.83 Option C: the caller's own customer-wrapped custodial blob for
|
|
4038
4096
|
* client-side message decryption. The blob is decryptable ONLY by the
|
|
@@ -4169,7 +4227,9 @@ var GldaiSubmodule = class {
|
|
|
4169
4227
|
this._t = transport;
|
|
4170
4228
|
this._base = baseUrl;
|
|
4171
4229
|
}
|
|
4172
|
-
/** GET /api/v1/companies (Class C, metered): charged_joules + the metering block (file header — read metering.settlement to know whether you paid).
|
|
4230
|
+
/** GET /api/v1/companies (Class C, metered): charged_joules + the metering block (file header — read metering.settlement to know whether you paid).
|
|
4231
|
+
* `country` matches on the country code: "USA", "US" and "United States" find the same rows, "Chile,Peru" finds either,
|
|
4232
|
+
* an unrecognised value is a partial-name match. Each company carries `country` and `country_code` (ISO 3166-1 alpha-2; null for a multi-country row). */
|
|
4173
4233
|
companies({ idempotencyKey, ...params } = {}) {
|
|
4174
4234
|
return this._t.request(this._base, "GET", "/api/v1/companies", { params, idempotencyKey });
|
|
4175
4235
|
}
|
|
@@ -4186,7 +4246,11 @@ var GldaiSubmodule = class {
|
|
|
4186
4246
|
* `commodity_filter` {query, matched_directly, matched_via_group} tells you which (matched_via_group
|
|
4187
4247
|
* names the group). Each deposit carries `commodities[]` {name, role:primary|byproduct, group};
|
|
4188
4248
|
* resource_type stays primary. The response also carries `charged_joules` (all-in metered cost; null
|
|
4189
|
-
* for a quota caller) and the metering block (file header). R6-C, 2026-09-22.
|
|
4249
|
+
* for a quota caller) and the metering block (file header). R6-C, 2026-09-22.
|
|
4250
|
+
* `country` / `owner_country` match on the country code: "USA", "US" and "United States" find the same rows, "Chile,Peru"
|
|
4251
|
+
* finds either, an unrecognised value is a partial-name match. Each deposit carries `country`, `country_code` (ISO 3166-1
|
|
4252
|
+
* alpha-2; null for a multi-country row), `country_codes`, `country_scope`, `country_input` (the text as the source stated
|
|
4253
|
+
* it) and the same five for the owner (`owner_country_*`). */
|
|
4190
4254
|
deposits({ idempotencyKey, ...params } = {}) {
|
|
4191
4255
|
return this._t.request(this._base, "GET", "/api/v1/deposits", { params, idempotencyKey });
|
|
4192
4256
|
}
|
|
@@ -4194,7 +4258,10 @@ var GldaiSubmodule = class {
|
|
|
4194
4258
|
deposit(depositId) {
|
|
4195
4259
|
return this._t.request(this._base, "GET", "/api/v1/deposits/{did}", { pathParams: { did: depositId } });
|
|
4196
4260
|
}
|
|
4197
|
-
/** GET /api/v1/infrastructure (Class C, metered): charged_joules + metering block (file header).
|
|
4261
|
+
/** GET /api/v1/infrastructure (Class C, metered): charged_joules + metering block (file header).
|
|
4262
|
+
* `country` / `owner_country` match on the country code ("USA", "US" and "United States" find the same rows; "Chile,Peru"
|
|
4263
|
+
* finds either; an unrecognised value is a partial-name match). Each asset carries `country`, `country_code` (ISO 3166-1
|
|
4264
|
+
* alpha-2; null for a multi-country row), `country_codes`, `country_scope`, `country_input` and the same five for the owner. */
|
|
4198
4265
|
infrastructureList({ idempotencyKey, ...params } = {}) {
|
|
4199
4266
|
return this._t.request(this._base, "GET", "/api/v1/infrastructure", { params, idempotencyKey });
|
|
4200
4267
|
}
|
|
@@ -4211,7 +4278,9 @@ var GldaiSubmodule = class {
|
|
|
4211
4278
|
query(q, { idempotencyKey, ...params } = {}) {
|
|
4212
4279
|
return this._t.request(this._base, "GET", "/api/v1/query", { params: { q, ...params }, idempotencyKey });
|
|
4213
4280
|
}
|
|
4214
|
-
/** GET /api/v1/projects (Class C, metered): charged_joules + metering block (file header).
|
|
4281
|
+
/** GET /api/v1/projects (Class C, metered): charged_joules + metering block (file header).
|
|
4282
|
+
* `country` matches on the country code ("USA", "US" and "United States" find the same rows; "Chile,Peru" finds either;
|
|
4283
|
+
* an unrecognised value is a partial-name match). Each project carries `country` and `country_code`. */
|
|
4215
4284
|
projects({ idempotencyKey, ...params } = {}) {
|
|
4216
4285
|
return this._t.request(this._base, "GET", "/api/v1/projects", { params, idempotencyKey });
|
|
4217
4286
|
}
|
|
@@ -4318,7 +4387,7 @@ var GldaiSubmodule = class {
|
|
|
4318
4387
|
return this._t.request(this._base, "GET", "/api/v1/map.viewport", { params, idempotencyKey });
|
|
4319
4388
|
}
|
|
4320
4389
|
/** GET /api/v1/look.at — a Sentinel-2 satellite STILL of a point (lat+lng) or an entity (entityType+id).
|
|
4321
|
-
* AGENT KEYS ONLY (a browser session
|
|
4390
|
+
* AGENT KEYS ONLY (a browser session is refused before any charge). Metered
|
|
4322
4391
|
* against the CALLING agent's wallet — its own price line (~150 J; quote with
|
|
4323
4392
|
* billingQuote("/api/v1/look.at")). On a hit returns { available: true, content_type: "image/jpeg",
|
|
4324
4393
|
* image_jpeg: Uint8Array, provenance: { X-* headers — scene date, source, … } }; on a cloudy/missing
|
|
@@ -4441,7 +4510,10 @@ var JoulepaiSubmodule = class {
|
|
|
4441
4510
|
}
|
|
4442
4511
|
return this._walletId;
|
|
4443
4512
|
}
|
|
4444
|
-
/** Absorbs Wallet.create (index.js:50).
|
|
4513
|
+
/** Absorbs Wallet.create (index.js:50). A SIGNED-IN SESSION, or an agent key its owner granted the custom scope
|
|
4514
|
+
* `wallet:create`: build the Client with your signed-in session (oauthToken: the ENYAL session from sign-in, or
|
|
4515
|
+
* joulepai.ai's own session JWT). Any other API key or OAuth token is refused 403 {"error":"scope_not_granted",
|
|
4516
|
+
* "scope":"wallet:create"} (ScopeError) — a person's own jlp_ wallet key carries no grant. POST /wallet/create. */
|
|
4445
4517
|
createWallet({ email, ownerId, ownerType = "human", handle }) {
|
|
4446
4518
|
const body = { owner_id: ownerId || crypto.randomUUID(), owner_type: ownerType, email };
|
|
4447
4519
|
if (handle) body.handle = handle;
|
|
@@ -4556,6 +4628,9 @@ var JoulepaiSubmodule = class {
|
|
|
4556
4628
|
{ pathParams: { wid: await this._ensureId() }, params: { limit, offset } }
|
|
4557
4629
|
);
|
|
4558
4630
|
}
|
|
4631
|
+
/** Set your wallet's handle. SESSION-ONLY — build the Client with your signed-in session (oauthToken: the ENYAL
|
|
4632
|
+
* session from sign-in, or joulepai.ai's own session JWT), NOT an API key or OAuth token (refused 403
|
|
4633
|
+
* {"error":"session_required"}, ScopeError). PUT /wallet/handle. */
|
|
4559
4634
|
async setHandle(h) {
|
|
4560
4635
|
return this._t.request(
|
|
4561
4636
|
this._base,
|
|
@@ -4580,6 +4655,9 @@ var JoulepaiSubmodule = class {
|
|
|
4580
4655
|
{ pathParams: { wid: await this._ensureId() } }
|
|
4581
4656
|
);
|
|
4582
4657
|
}
|
|
4658
|
+
/** Set the wallet's spending limits. SESSION-ONLY — build the Client with your signed-in session (oauthToken: the
|
|
4659
|
+
* ENYAL session from sign-in, or joulepai.ai's own session JWT), NOT an API key or OAuth token (refused 403
|
|
4660
|
+
* {"error":"session_required"}, ScopeError). Reading them (getLimits) is unchanged. PUT /wallet/limits. */
|
|
4583
4661
|
async setLimits({ daily, perTransaction, allowedPlatforms } = {}) {
|
|
4584
4662
|
const body = { agent_wallet_id: await this._ensureId() };
|
|
4585
4663
|
if (daily != null) body.daily_cap = daily;
|
|
@@ -4644,6 +4722,10 @@ var JoulepaiSubmodule = class {
|
|
|
4644
4722
|
note: live ? "USDC on Base is live \u2014 deposit to your Base address above (min 5 USDC), credited automatically; track it with depositStatus(). Do not follow a URL to fund." : "No in-band USDC address available for this credential; fund with card meanwhile. Do not follow a URL to fund."
|
|
4645
4723
|
};
|
|
4646
4724
|
}
|
|
4725
|
+
/** For a lost API key; no sign-in needed (the wallet id + the wallet's email). Nothing is rotated and no key is sent:
|
|
4726
|
+
* the wallet's email is told how to get a new key — sign in at joulepai.ai, Dashboard → API Credentials
|
|
4727
|
+
* (POST /wallet/regenerate-key, signed-in owner only), where the new key is shown once. The current key keeps working
|
|
4728
|
+
* until then. POST /wallet/reset-credentials. */
|
|
4647
4729
|
resetCredentials(walletId, email) {
|
|
4648
4730
|
return this._t.request(
|
|
4649
4731
|
this._base,
|
|
@@ -4731,14 +4813,17 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
|
|
|
4731
4813
|
"speed",
|
|
4732
4814
|
"privacy_mode",
|
|
4733
4815
|
"contract_escrow",
|
|
4734
|
-
"
|
|
4816
|
+
"physical_claim",
|
|
4817
|
+
"idempotency_key",
|
|
4818
|
+
"provider_id"
|
|
4735
4819
|
]),
|
|
4820
|
+
// P-DAY.133 item 3: RAREEAI honours it (matches that listing only; 404 when invalid)
|
|
4736
4821
|
dispute: /* @__PURE__ */ new Set(["reason"]),
|
|
4737
4822
|
resolve: /* @__PURE__ */ new Set(["resolution", "split_pct"]),
|
|
4738
4823
|
deliver: /* @__PURE__ */ new Set(),
|
|
4739
4824
|
approve: /* @__PURE__ */ new Set(),
|
|
4740
4825
|
reject: /* @__PURE__ */ new Set(),
|
|
4741
|
-
extend_dispute: /* @__PURE__ */ new Set()
|
|
4826
|
+
extend_dispute: /* @__PURE__ */ new Set(["until"])
|
|
4742
4827
|
};
|
|
4743
4828
|
/** Keep only fields the backend model for `kind` accepts; refuse the rest by name. */
|
|
4744
4829
|
static _body(kind, fields) {
|
|
@@ -4760,6 +4845,8 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
|
|
|
4760
4845
|
}
|
|
4761
4846
|
// ENFORCED-WHEN-PRESENT / BEST-EFFORT-keyless (routes.py:1282 guard; SDK dispatch
|
|
4762
4847
|
// always auto-gens a key → SDK callers effectively enforced; keyless gap raw-HTTP-only).
|
|
4848
|
+
// 0.5.18: resourceType scene_stack / change_report / site_reconstruction / satellite_imagery MUST pass physical_claim
|
|
4849
|
+
// { kind: 'physical_change'|'physical_state', site_lat, site_lng, t1, t0 (a change), radius_m? } — RAREEAI refuses it otherwise.
|
|
4763
4850
|
createRequest({ resourceType, idempotencyKey, retry = true, ...fields }) {
|
|
4764
4851
|
return this._t.request(
|
|
4765
4852
|
this._base,
|
|
@@ -4832,12 +4919,14 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
|
|
|
4832
4919
|
{ pathParams: { match_id: matchId }, body: _RareeaiSubmodule._body("dispute", fields) }
|
|
4833
4920
|
);
|
|
4834
4921
|
}
|
|
4835
|
-
|
|
4922
|
+
// Offer, or agree to, a FIXED later dispute deadline (P-DAY.133): both parties send the same `until` (ISO 8601 with a timezone);
|
|
4923
|
+
// the first call is an offer, the other party's identical call is the extension. NOT retry-safe.
|
|
4924
|
+
extendDispute(matchId, until, fields = {}) {
|
|
4836
4925
|
return this._t.request(
|
|
4837
4926
|
this._base,
|
|
4838
4927
|
"POST",
|
|
4839
4928
|
`${this._p}/match/{match_id}/extend-dispute`,
|
|
4840
|
-
{ pathParams: { match_id: matchId }, body: _RareeaiSubmodule._body("extend_dispute", fields) }
|
|
4929
|
+
{ pathParams: { match_id: matchId }, body: _RareeaiSubmodule._body("extend_dispute", { until, ...fields }) }
|
|
4841
4930
|
);
|
|
4842
4931
|
}
|
|
4843
4932
|
// reads
|
|
@@ -4937,7 +5026,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
|
|
|
4937
5026
|
};
|
|
4938
5027
|
|
|
4939
5028
|
// index.js
|
|
4940
|
-
var VERSION = "0.
|
|
5029
|
+
var VERSION = "3.0.1";
|
|
4941
5030
|
var Client = class {
|
|
4942
5031
|
/**
|
|
4943
5032
|
* @param {object} opts
|
package/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export {
|
|
|
16
16
|
export { ENFORCED, NOT_SUPPORTED, SAFE, IDEMPOTENCY_MAP } from "./src/core/idempotency.js";
|
|
17
17
|
export * as crypto from "./src/core/crypto.js";
|
|
18
18
|
|
|
19
|
-
export const VERSION = "0.
|
|
19
|
+
export const VERSION = "3.0.1";
|
|
20
20
|
|
|
21
21
|
export class Client {
|
|
22
22
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greenlandai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Unified SDK for the GreenlandAI ecosystem (ENYAL, JoulePAI, RAREEAI, GreenlandAI)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://greenlandai.ai",
|
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
".": {
|
|
14
14
|
"import": "./index.js",
|
|
15
15
|
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./messaging_v4.js": {
|
|
18
|
+
"import": "./src/core/messaging_v4.js"
|
|
19
|
+
},
|
|
20
|
+
"./messaging_client.js": {
|
|
21
|
+
"import": "./src/core/messaging_client.js"
|
|
22
|
+
},
|
|
23
|
+
"./messaging_store_node.js": {
|
|
24
|
+
"import": "./src/core/messaging_store_node.js"
|
|
16
25
|
}
|
|
17
26
|
},
|
|
18
27
|
"files": [
|
package/src/core/crypto.js
CHANGED
|
@@ -554,9 +554,39 @@ function _bytesToBase64(u8) {
|
|
|
554
554
|
|
|
555
555
|
/** Parse a v5/v6 message blob into the {encryption_metadata, encrypted_payload}
|
|
556
556
|
* chunk shape decryptDisclosedChunk expects. */
|
|
557
|
+
/**
|
|
558
|
+
* A message cannot be opened with your keys (P-DAY.127). `code`: missing_payload · legacy_message (crypto_version 1, sent
|
|
559
|
+
* before 2026-08-16, encrypted to the platform) · messaging_upgrade_required (an end-to-end v4 message: upgrade the SDK) ·
|
|
560
|
+
* bad_encoding · unknown_version (upgrade the SDK) · truncated. A wrong share
|
|
561
|
+
* or a tampered ciphertext is NOT this error: it fails the AES-GCM tag check. Same codes as @enyalai/sdk and the Python SDKs.
|
|
562
|
+
*/
|
|
563
|
+
export class MessageFormatError extends Error {
|
|
564
|
+
constructor(code, message) {
|
|
565
|
+
super(message);
|
|
566
|
+
this.name = "MessageFormatError";
|
|
567
|
+
this.code = code;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export const MESSAGE_BLOB_VERSIONS = [5, 6];
|
|
572
|
+
|
|
557
573
|
function _messageBlobToChunk(payloadBase64) {
|
|
558
|
-
|
|
574
|
+
// P-DAY.127: refuse an unknown version or a short blob instead of mis-parsing it.
|
|
575
|
+
const s = String(payloadBase64);
|
|
576
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(s) || s.length % 4 !== 0) {
|
|
577
|
+
throw new MessageFormatError("bad_encoding", "encrypted_payload is not valid base64");
|
|
578
|
+
}
|
|
579
|
+
const blob = base64ToBytes(s);
|
|
580
|
+
if (blob.length < 2) throw new MessageFormatError("truncated", `message blob is ${blob.length} bytes — too short to carry a version`);
|
|
559
581
|
const version = (blob[0] << 8) | blob[1];
|
|
582
|
+
if (!MESSAGE_BLOB_VERSIONS.includes(version)) {
|
|
583
|
+
throw new MessageFormatError("unknown_version",
|
|
584
|
+
`message blob version 0x${version.toString(16).padStart(4, "0")} is not one this SDK opens — upgrade the SDK`);
|
|
585
|
+
}
|
|
586
|
+
const fixed = 2 + _MSG_EPHEM_LEN + (version === 6 ? _MSG_MLKEM_LEN : 0) + _MSG_NONCE_LEN + _MSG_TAG_LEN;
|
|
587
|
+
if (blob.length <= fixed) {
|
|
588
|
+
throw new MessageFormatError("truncated", `v${version} message blob is ${blob.length} bytes; it needs more than ${fixed}`);
|
|
589
|
+
}
|
|
560
590
|
let off = 2;
|
|
561
591
|
const ephem = blob.slice(off, off + _MSG_EPHEM_LEN); off += _MSG_EPHEM_LEN;
|
|
562
592
|
let mlkemCt = null;
|
|
@@ -607,7 +637,16 @@ export function mnemonicToCustomerShare(mnemonic) {
|
|
|
607
637
|
* @returns {Promise<string>} the decrypted plaintext (UTF-8)
|
|
608
638
|
*/
|
|
609
639
|
export async function decryptMessage({ message, wrapped, customerShare, recoveryPhrase, p256ScalarMul }) {
|
|
610
|
-
if (!message || !message.encrypted_payload) throw new
|
|
640
|
+
if (!message || !message.encrypted_payload) throw new MessageFormatError("missing_payload", "message.encrypted_payload required");
|
|
641
|
+
if (message.crypto_version === 1) {
|
|
642
|
+
throw new MessageFormatError("legacy_message", "this message (crypto_version 1, sent before 2026-08-16) was encrypted " +
|
|
643
|
+
"to the platform, not to your keys — it cannot be opened here");
|
|
644
|
+
}
|
|
645
|
+
// A messaging v4 (end-to-end) message: refuse it first, before any key is asked for (plan §6).
|
|
646
|
+
if (message.crypto_version === 4 || /^(eyJ|\{)/.test(String(message.encrypted_payload))) {
|
|
647
|
+
throw new MessageFormatError("messaging_upgrade_required", "this message is end-to-end encrypted (messaging v4) and " +
|
|
648
|
+
"this SDK cannot open it — upgrade to @greenlandai/sdk 1.0.0 or later");
|
|
649
|
+
}
|
|
611
650
|
if (!wrapped) throw new ValidationError(null, "wrapped custodial share required (GET /message/my-keys)");
|
|
612
651
|
let share;
|
|
613
652
|
if (customerShare) {
|
|
@@ -617,8 +656,8 @@ export async function decryptMessage({ message, wrapped, customerShare, recovery
|
|
|
617
656
|
} else {
|
|
618
657
|
throw new ValidationError(null, "provide customerShare or recoveryPhrase");
|
|
619
658
|
}
|
|
659
|
+
const chunk = _messageBlobToChunk(message.encrypted_payload); // format checks first — no key work for a bad blob
|
|
620
660
|
const custodial = await decryptCustodialShare(share, wrapped);
|
|
621
|
-
const chunk = _messageBlobToChunk(message.encrypted_payload);
|
|
622
661
|
const pt = await decryptDisclosedChunk(share, custodial, chunk, p256ScalarMul);
|
|
623
662
|
return new TextDecoder().decode(pt);
|
|
624
663
|
}
|