@greenlandai/sdk 0.5.15 → 0.5.17
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 +19 -0
- package/dist/index.cjs +43 -6
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/core/crypto.js +36 -3
- package/src/core/transport.js +16 -1
- package/src/gldai.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## 0.5.17 (2026-10-04)
|
|
2
|
+
- **`decrypt_message` / `crypto.decryptMessage` refuse what they cannot open instead of mis-reading it.** A crypto_version 1
|
|
3
|
+
message (sent before 2026-08-16, encrypted to the platform), a blob version other than v5 / v6, a blob shorter than its format
|
|
4
|
+
or a non-base64 payload now raise `MessageFormatError` with a `code` (legacy_message, unknown_version, truncated,
|
|
5
|
+
bad_encoding, missing_payload) — the format is checked before any key work. Until now an unknown or short blob was parsed
|
|
6
|
+
anyway and failed later as a generic decryption error, and a legacy message was attempted. A wrong share or a tampered
|
|
7
|
+
message still fails the AES-GCM check. The helper is now in the interop KAT (checks xi–xviii, against blobs the ENYAL server
|
|
8
|
+
encrypted); it had no test before. Same codes as enyal-sdk / @enyalai/sdk 2.2.14.
|
|
9
|
+
- Docstrings: "developer key" wording removed (personal gai_ keys are retired).
|
|
10
|
+
|
|
11
|
+
## 0.5.16 (2026-10-03)
|
|
12
|
+
- **A missing path id is refused before any request** (all 29 methods that put an id in the URL path: ENYAL lineage / thread /
|
|
13
|
+
knowledge nodes, GreenlandAI company / deposit / infrastructure / project, RAREEAI match actions, JoulePAI wallet / transfer /
|
|
14
|
+
funding). None / undefined, a non-string (an integer is allowed), an empty or blank string, or the text a missing value turns
|
|
15
|
+
into ("undefined", "null", "None", "NaN") raise `ValueError` (Python) / `TypeError` (JS). Until now the request went out with
|
|
16
|
+
"None" / "undefined" in the path.
|
|
17
|
+
- **Path ids are percent-encoded as one segment in Python too** (JS already encoded them). Until now the Python client sent an id
|
|
18
|
+
raw, so an id containing "/", "?" or "#" reached a different route.
|
|
19
|
+
|
|
1
20
|
## 0.5.15 (2026-10-01)
|
|
2
21
|
- **GreenlandAI's graph answers are about ONE entity** (GreenlandAI 8c0ec77). `client.gldai.relationships()` takes `entityType`
|
|
3
22
|
("company" | "infrastructure" | "deposit" | "project") + `entityId` to pin the start node; `entity` resolves to the one entity
|
package/dist/index.cjs
CHANGED
|
@@ -229,6 +229,15 @@ var noopLogger = { debug() {
|
|
|
229
229
|
}, warn() {
|
|
230
230
|
}, error() {
|
|
231
231
|
} };
|
|
232
|
+
var _MISSING_ID_TEXT = /* @__PURE__ */ new Set(["", "undefined", "null", "none", "nan"]);
|
|
233
|
+
function _pathId(name, value) {
|
|
234
|
+
const ok = typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
235
|
+
if (!ok) {
|
|
236
|
+
throw new TypeError(`${name} must be a non-empty string id (got ${value === null ? "null" : Array.isArray(value) ? "array" : typeof value}); no request was sent`);
|
|
237
|
+
}
|
|
238
|
+
if (_MISSING_ID_TEXT.has(String(value).trim().toLowerCase())) throw new TypeError(`${name} is empty or missing; no request was sent`);
|
|
239
|
+
return encodeURIComponent(String(value));
|
|
240
|
+
}
|
|
232
241
|
var Transport = class {
|
|
233
242
|
constructor({
|
|
234
243
|
apiKey,
|
|
@@ -281,7 +290,7 @@ var Transport = class {
|
|
|
281
290
|
headers = d.headers;
|
|
282
291
|
if (d.tier === NOT_SUPPORTED) retry = false;
|
|
283
292
|
let path = pathTemplate;
|
|
284
|
-
for (const [k, v] of Object.entries(pathParams)) path = path.replace(`{${k}}`,
|
|
293
|
+
for (const [k, v] of Object.entries(pathParams)) path = path.replace(`{${k}}`, _pathId(k, v));
|
|
285
294
|
let url = `${baseUrl.replace(/\/+$/, "")}${path}`;
|
|
286
295
|
if (params) {
|
|
287
296
|
const qs = new URLSearchParams(
|
|
@@ -388,6 +397,8 @@ var Transport = class {
|
|
|
388
397
|
var crypto_exports = {};
|
|
389
398
|
__export(crypto_exports, {
|
|
390
399
|
HASH_SCHEME_COMMIT_V1: () => HASH_SCHEME_COMMIT_V1,
|
|
400
|
+
MESSAGE_BLOB_VERSIONS: () => MESSAGE_BLOB_VERSIONS,
|
|
401
|
+
MessageFormatError: () => MessageFormatError,
|
|
391
402
|
RecordIntegrityError: () => RecordIntegrityError,
|
|
392
403
|
ZK_ENVELOPE_MAGIC: () => ZK_ENVELOPE_MAGIC,
|
|
393
404
|
ZK_ENVELOPE_R_LEN: () => ZK_ENVELOPE_R_LEN,
|
|
@@ -3833,9 +3844,32 @@ function _bytesToBase64(u8) {
|
|
|
3833
3844
|
for (let i = 0; i < u8.length; i++) s += String.fromCharCode(u8[i]);
|
|
3834
3845
|
return btoa(s);
|
|
3835
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];
|
|
3836
3855
|
function _messageBlobToChunk(payloadBase64) {
|
|
3837
|
-
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`);
|
|
3838
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
|
+
}
|
|
3839
3873
|
let off = 2;
|
|
3840
3874
|
const ephem = blob.slice(off, off + _MSG_EPHEM_LEN);
|
|
3841
3875
|
off += _MSG_EPHEM_LEN;
|
|
@@ -3868,7 +3902,10 @@ function mnemonicToCustomerShare(mnemonic) {
|
|
|
3868
3902
|
return share;
|
|
3869
3903
|
}
|
|
3870
3904
|
async function decryptMessage({ message, wrapped, customerShare, recoveryPhrase, p256ScalarMul }) {
|
|
3871
|
-
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
|
+
}
|
|
3872
3909
|
if (!wrapped) throw new ValidationError(null, "wrapped custodial share required (GET /message/my-keys)");
|
|
3873
3910
|
let share;
|
|
3874
3911
|
if (customerShare) {
|
|
@@ -3878,8 +3915,8 @@ async function decryptMessage({ message, wrapped, customerShare, recoveryPhrase,
|
|
|
3878
3915
|
} else {
|
|
3879
3916
|
throw new ValidationError(null, "provide customerShare or recoveryPhrase");
|
|
3880
3917
|
}
|
|
3881
|
-
const custodial = await decryptCustodialShare(share, wrapped);
|
|
3882
3918
|
const chunk = _messageBlobToChunk(message.encrypted_payload);
|
|
3919
|
+
const custodial = await decryptCustodialShare(share, wrapped);
|
|
3883
3920
|
const pt = await decryptDisclosedChunk(share, custodial, chunk, p256ScalarMul);
|
|
3884
3921
|
return new TextDecoder().decode(pt);
|
|
3885
3922
|
}
|
|
@@ -4309,7 +4346,7 @@ var GldaiSubmodule = class {
|
|
|
4309
4346
|
return this._t.request(this._base, "GET", "/api/v1/map.viewport", { params, idempotencyKey });
|
|
4310
4347
|
}
|
|
4311
4348
|
/** GET /api/v1/look.at — a Sentinel-2 satellite STILL of a point (lat+lng) or an entity (entityType+id).
|
|
4312
|
-
* AGENT KEYS ONLY (a browser session
|
|
4349
|
+
* AGENT KEYS ONLY (a browser session is refused before any charge). Metered
|
|
4313
4350
|
* against the CALLING agent's wallet — its own price line (~150 J; quote with
|
|
4314
4351
|
* billingQuote("/api/v1/look.at")). On a hit returns { available: true, content_type: "image/jpeg",
|
|
4315
4352
|
* image_jpeg: Uint8Array, provenance: { X-* headers — scene date, source, … } }; on a cloudy/missing
|
|
@@ -4928,7 +4965,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
|
|
|
4928
4965
|
};
|
|
4929
4966
|
|
|
4930
4967
|
// index.js
|
|
4931
|
-
var VERSION = "0.5.
|
|
4968
|
+
var VERSION = "0.5.17";
|
|
4932
4969
|
var Client = class {
|
|
4933
4970
|
/**
|
|
4934
4971
|
* @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.5.
|
|
19
|
+
export const VERSION = "0.5.17";
|
|
20
20
|
|
|
21
21
|
export class Client {
|
|
22
22
|
/**
|
package/package.json
CHANGED
package/src/core/crypto.js
CHANGED
|
@@ -554,9 +554,38 @@ 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) · bad_encoding · unknown_version (upgrade the SDK) · truncated. A wrong share
|
|
560
|
+
* or a tampered ciphertext is NOT this error: it fails the AES-GCM tag check. Same codes as @enyalai/sdk and the Python SDKs.
|
|
561
|
+
*/
|
|
562
|
+
export class MessageFormatError extends Error {
|
|
563
|
+
constructor(code, message) {
|
|
564
|
+
super(message);
|
|
565
|
+
this.name = "MessageFormatError";
|
|
566
|
+
this.code = code;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export const MESSAGE_BLOB_VERSIONS = [5, 6];
|
|
571
|
+
|
|
557
572
|
function _messageBlobToChunk(payloadBase64) {
|
|
558
|
-
|
|
573
|
+
// P-DAY.127: refuse an unknown version or a short blob instead of mis-parsing it.
|
|
574
|
+
const s = String(payloadBase64);
|
|
575
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(s) || s.length % 4 !== 0) {
|
|
576
|
+
throw new MessageFormatError("bad_encoding", "encrypted_payload is not valid base64");
|
|
577
|
+
}
|
|
578
|
+
const blob = base64ToBytes(s);
|
|
579
|
+
if (blob.length < 2) throw new MessageFormatError("truncated", `message blob is ${blob.length} bytes — too short to carry a version`);
|
|
559
580
|
const version = (blob[0] << 8) | blob[1];
|
|
581
|
+
if (!MESSAGE_BLOB_VERSIONS.includes(version)) {
|
|
582
|
+
throw new MessageFormatError("unknown_version",
|
|
583
|
+
`message blob version 0x${version.toString(16).padStart(4, "0")} is not one this SDK opens — upgrade the SDK`);
|
|
584
|
+
}
|
|
585
|
+
const fixed = 2 + _MSG_EPHEM_LEN + (version === 6 ? _MSG_MLKEM_LEN : 0) + _MSG_NONCE_LEN + _MSG_TAG_LEN;
|
|
586
|
+
if (blob.length <= fixed) {
|
|
587
|
+
throw new MessageFormatError("truncated", `v${version} message blob is ${blob.length} bytes; it needs more than ${fixed}`);
|
|
588
|
+
}
|
|
560
589
|
let off = 2;
|
|
561
590
|
const ephem = blob.slice(off, off + _MSG_EPHEM_LEN); off += _MSG_EPHEM_LEN;
|
|
562
591
|
let mlkemCt = null;
|
|
@@ -607,7 +636,11 @@ export function mnemonicToCustomerShare(mnemonic) {
|
|
|
607
636
|
* @returns {Promise<string>} the decrypted plaintext (UTF-8)
|
|
608
637
|
*/
|
|
609
638
|
export async function decryptMessage({ message, wrapped, customerShare, recoveryPhrase, p256ScalarMul }) {
|
|
610
|
-
if (!message || !message.encrypted_payload) throw new
|
|
639
|
+
if (!message || !message.encrypted_payload) throw new MessageFormatError("missing_payload", "message.encrypted_payload required");
|
|
640
|
+
if (message.crypto_version === 1) {
|
|
641
|
+
throw new MessageFormatError("legacy_message", "this message (crypto_version 1, sent before 2026-08-16) was encrypted " +
|
|
642
|
+
"to the platform, not to your keys — it cannot be opened here");
|
|
643
|
+
}
|
|
611
644
|
if (!wrapped) throw new ValidationError(null, "wrapped custodial share required (GET /message/my-keys)");
|
|
612
645
|
let share;
|
|
613
646
|
if (customerShare) {
|
|
@@ -617,8 +650,8 @@ export async function decryptMessage({ message, wrapped, customerShare, recovery
|
|
|
617
650
|
} else {
|
|
618
651
|
throw new ValidationError(null, "provide customerShare or recoveryPhrase");
|
|
619
652
|
}
|
|
653
|
+
const chunk = _messageBlobToChunk(message.encrypted_payload); // format checks first — no key work for a bad blob
|
|
620
654
|
const custodial = await decryptCustodialShare(share, wrapped);
|
|
621
|
-
const chunk = _messageBlobToChunk(message.encrypted_payload);
|
|
622
655
|
const pt = await decryptDisclosedChunk(share, custodial, chunk, p256ScalarMul);
|
|
623
656
|
return new TextDecoder().decode(pt);
|
|
624
657
|
}
|
package/src/core/transport.js
CHANGED
|
@@ -69,6 +69,21 @@ function isRetryable(err) {
|
|
|
69
69
|
|
|
70
70
|
const noopLogger = { debug() {}, info() {}, warn() {}, error() {} };
|
|
71
71
|
|
|
72
|
+
// A record id in a URL path (P-DAY.126, operator: "/lineage/undefined is our client letting a bad call through"). Every path id goes
|
|
73
|
+
// through here (29 call sites): a missing id is refused BEFORE any request — undefined, null, a non-string (a finite number is allowed),
|
|
74
|
+
// an empty or blank string, or the text a missing value turns into ('undefined', 'null', 'None', 'NaN'); a real id is sent as ONE
|
|
75
|
+
// percent-encoded path segment. The error names the parameter and the type only — never the value.
|
|
76
|
+
const _MISSING_ID_TEXT = new Set(["", "undefined", "null", "none", "nan"]);
|
|
77
|
+
|
|
78
|
+
function _pathId(name, value) {
|
|
79
|
+
const ok = typeof value === "string" || (typeof value === "number" && Number.isFinite(value));
|
|
80
|
+
if (!ok) {
|
|
81
|
+
throw new TypeError(`${name} must be a non-empty string id (got ${value === null ? "null" : Array.isArray(value) ? "array" : typeof value}); no request was sent`);
|
|
82
|
+
}
|
|
83
|
+
if (_MISSING_ID_TEXT.has(String(value).trim().toLowerCase())) throw new TypeError(`${name} is empty or missing; no request was sent`);
|
|
84
|
+
return encodeURIComponent(String(value));
|
|
85
|
+
}
|
|
86
|
+
|
|
72
87
|
export class Transport {
|
|
73
88
|
constructor({ apiKey, oauthToken, logger, onRetry, onTerminalFailure,
|
|
74
89
|
onAuthExpired, metrics, fetchImpl } = {}) {
|
|
@@ -115,7 +130,7 @@ export class Transport {
|
|
|
115
130
|
if (d.tier === NOT_SUPPORTED) retry = false; // §3.1 layered rule
|
|
116
131
|
|
|
117
132
|
let path = pathTemplate;
|
|
118
|
-
for (const [k, v] of Object.entries(pathParams)) path = path.replace(`{${k}}`,
|
|
133
|
+
for (const [k, v] of Object.entries(pathParams)) path = path.replace(`{${k}}`, _pathId(k, v));
|
|
119
134
|
let url = `${baseUrl.replace(/\/+$/, "")}${path}`;
|
|
120
135
|
if (params) {
|
|
121
136
|
const qs = new URLSearchParams(
|
package/src/gldai.js
CHANGED
|
@@ -152,7 +152,7 @@ export class GldaiSubmodule {
|
|
|
152
152
|
return this._t.request(this._base, "GET", "/api/v1/map.viewport", { params, idempotencyKey });
|
|
153
153
|
}
|
|
154
154
|
/** GET /api/v1/look.at — a Sentinel-2 satellite STILL of a point (lat+lng) or an entity (entityType+id).
|
|
155
|
-
* AGENT KEYS ONLY (a browser session
|
|
155
|
+
* AGENT KEYS ONLY (a browser session is refused before any charge). Metered
|
|
156
156
|
* against the CALLING agent's wallet — its own price line (~150 J; quote with
|
|
157
157
|
* billingQuote("/api/v1/look.at")). On a hit returns { available: true, content_type: "image/jpeg",
|
|
158
158
|
* image_jpeg: Uint8Array, provenance: { X-* headers — scene date, source, … } }; on a cloudy/missing
|