@greenlandai/sdk 0.5.16 → 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 +10 -0
- package/dist/index.cjs +33 -5
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/core/crypto.js +36 -3
- package/src/gldai.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
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
|
+
|
|
1
11
|
## 0.5.16 (2026-10-03)
|
|
2
12
|
- **A missing path id is refused before any request** (all 29 methods that put an id in the URL path: ENYAL lineage / thread /
|
|
3
13
|
knowledge nodes, GreenlandAI company / deposit / infrastructure / project, RAREEAI match actions, JoulePAI wallet / transfer /
|
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,10 @@ 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
|
+
}
|
|
3881
3909
|
if (!wrapped) throw new ValidationError(null, "wrapped custodial share required (GET /message/my-keys)");
|
|
3882
3910
|
let share;
|
|
3883
3911
|
if (customerShare) {
|
|
@@ -3887,8 +3915,8 @@ async function decryptMessage({ message, wrapped, customerShare, recoveryPhrase,
|
|
|
3887
3915
|
} else {
|
|
3888
3916
|
throw new ValidationError(null, "provide customerShare or recoveryPhrase");
|
|
3889
3917
|
}
|
|
3890
|
-
const custodial = await decryptCustodialShare(share, wrapped);
|
|
3891
3918
|
const chunk = _messageBlobToChunk(message.encrypted_payload);
|
|
3919
|
+
const custodial = await decryptCustodialShare(share, wrapped);
|
|
3892
3920
|
const pt = await decryptDisclosedChunk(share, custodial, chunk, p256ScalarMul);
|
|
3893
3921
|
return new TextDecoder().decode(pt);
|
|
3894
3922
|
}
|
|
@@ -4318,7 +4346,7 @@ var GldaiSubmodule = class {
|
|
|
4318
4346
|
return this._t.request(this._base, "GET", "/api/v1/map.viewport", { params, idempotencyKey });
|
|
4319
4347
|
}
|
|
4320
4348
|
/** 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
|
|
4349
|
+
* AGENT KEYS ONLY (a browser session is refused before any charge). Metered
|
|
4322
4350
|
* against the CALLING agent's wallet — its own price line (~150 J; quote with
|
|
4323
4351
|
* billingQuote("/api/v1/look.at")). On a hit returns { available: true, content_type: "image/jpeg",
|
|
4324
4352
|
* image_jpeg: Uint8Array, provenance: { X-* headers — scene date, source, … } }; on a cloudy/missing
|
|
@@ -4937,7 +4965,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
|
|
|
4937
4965
|
};
|
|
4938
4966
|
|
|
4939
4967
|
// index.js
|
|
4940
|
-
var VERSION = "0.5.
|
|
4968
|
+
var VERSION = "0.5.17";
|
|
4941
4969
|
var Client = class {
|
|
4942
4970
|
/**
|
|
4943
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/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
|