@greenlandai/sdk 3.0.2 → 3.1.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/CHANGELOG.md CHANGED
@@ -1,11 +1,17 @@
1
- ## 3.0.2 (2026-11-02)
2
- Only this change since 3.0.1 (built from 3.0.1's tree; the later unreleased work stays for its own release):
3
- - **The anchor check survives a reorg** (messaging v4 SPEC §15, the rule of enyal-verify 0.1.4). The anchored-transaction fetch asks every
4
- BSV source, and a source counts only when the block it names is its OWN main-chain block at that height. A source still on an orphaned
5
- block is reported in `stale`, one that cannot answer (rate limit, outage, not yet in a block) in `unavailable`; neither is counted. At
6
- least 2 counted sources must agree. WhatsOnChain is added as a third default source (`BSV_SOURCES`; a source needs a `chain` height
7
- index). Bytes that hash to another txid still refuse. Real case: 2026-11-02, one source still indexed a transaction in orphaned block
8
- 973536 while two others had it at 973539 — 3.0.1 refused it ("the sources disagree on the block"); 3.0.2 accepts it.
1
+ ## 3.1.0 (unreleased — publishes on the operator's GO)
2
+ - **Malformed v6 metadata is named as such** — `combineSharesAndDecryptHybrid` (and so `decryptDisclosedChunk` on a v6 chunk)
3
+ checks that `ecdh_public_key_hex` is 33 bytes and `mlkem_ciphertext_hex` is 1088 bytes before using either, and says which field
4
+ is wrong. Before, a wrong length surfaced at the AES-GCM tag as "invalid recovery phrase or share". A wrong share still gives that
5
+ message. Same change in `enyal-sdk` and `@enyalai/sdk`.
6
+ - **Your account's post-quantum key (ML-KEM a3(a))** — `enyal.registerMlkemKey({ recoveryPhrase | customerShare })`: an ENYAL account made before 2026-07-10 registers its ML-KEM-768 key, derived on this device from the customer share and signed by the account key (ENYAL's POST /message/my-keys/mlkem). Tests: test/p160-mlkem-key-registration.test.js.
7
+ - **Post-quantum disclosures (ML-KEM a3(b))** — `disclose(…, { recipientMlkemEkHex })` asks ENYAL to re-encrypt to the recipient's ML-KEM-768 key (payload_version 6).
8
+ - Carries 3.0.2's fix (the anchor check survives a reorg): 3.0.2 was published from an isolated branch; master has had the same files.
9
+ - And everything below under "Unreleased".
10
+
11
+ ## Unreleased
12
+ - `gldai.signals(kind, country, limit)` — the live signal cards (GET /api/v1/signals; Signal Engine S8, P-DAY.137): the three
13
+ families, each card with its answer_sha256 and, once the ranked feed is live, rank_score + parts; 0 cards while no type is armed (0 J);
14
+ metered per card delivered; never advice. Parity with the MCP `signals` tool.
9
15
 
10
16
  ## 3.0.1 (2026-10-18)
11
17
  The first published release since 0.5.17: it carries everything listed below under "Unreleased" (the messaging v4 client of
package/README.md CHANGED
@@ -62,6 +62,12 @@ billing_quote (free). Live totals: `GET https://greenlandai.ai/api/v1/public/sta
62
62
  before any charge — use the structured reads. The bulk map-layers route `/mapdata` was retired on 2026-09-30
63
63
  (it answers 404) and its SDK method removed in 0.5.13 — use mapViewport for map reads.
64
64
 
65
+ `client.gldai.signals({ kind, country, limit })` reads the live signal cards (GET /api/v1/signals, the Signal Engine's one read:
66
+ lead_lag, network and signature families, each card a compiled answer with its answer_sha256 and, once the ranked feed is live, a
67
+ rank_score with its parts); a type serves cards only while armed, and no type is armed yet, so it answers 0 cards today at no
68
+ charge; metered per card delivered (200 J a card today) — quote first with billingQuote("/api/v1/signals"). Signals are measured
69
+ observations with their provenance, never advice.
70
+
65
71
  ## ENYAL: zero-knowledge records, proof refusals and binding notes (0.5.13)
66
72
 
67
73
  - **Zero-knowledge records.** A record archived by a zero-knowledge account after ENYAL's #6 change decrypts to
package/dist/index.cjs CHANGED
@@ -417,6 +417,8 @@ __export(crypto_exports, {
417
417
  hexToBytes: () => hexToBytes3,
418
418
  hkdfSha256: () => hkdfSha256,
419
419
  hybridKDF: () => hybridKDF,
420
+ mlkemKeyRegistration: () => mlkemKeyRegistration,
421
+ mlkemKeyRegistrationMessage: () => mlkemKeyRegistrationMessage,
420
422
  mnemonicToCustomerShare: () => mnemonicToCustomerShare,
421
423
  openRecord: () => openRecord,
422
424
  p256SharedSecretX: () => p256SharedSecretX,
@@ -427,7 +429,7 @@ __export(crypto_exports, {
427
429
  var import_bip39 = require("@scure/bip39");
428
430
  var import_english = require("@scure/bip39/wordlists/english");
429
431
 
430
- // node_modules/@noble/post-quantum/node_modules/@noble/hashes/_u64.js
432
+ // ../../node_modules/@noble/post-quantum/node_modules/@noble/hashes/_u64.js
431
433
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
432
434
  var _32n = /* @__PURE__ */ BigInt(32);
433
435
  function fromBig(n, le = false) {
@@ -450,7 +452,7 @@ var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
450
452
  var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
451
453
  var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
452
454
 
453
- // node_modules/@noble/post-quantum/node_modules/@noble/hashes/utils.js
455
+ // ../../node_modules/@noble/post-quantum/node_modules/@noble/hashes/utils.js
454
456
  function isBytes(a) {
455
457
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
456
458
  }
@@ -536,7 +538,7 @@ var oidNist = (suffix) => ({
536
538
  oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
537
539
  });
538
540
 
539
- // node_modules/@noble/post-quantum/node_modules/@noble/hashes/sha3.js
541
+ // ../../node_modules/@noble/post-quantum/node_modules/@noble/hashes/sha3.js
540
542
  var _0n = BigInt(0);
541
543
  var _1n = BigInt(1);
542
544
  var _2n = BigInt(2);
@@ -750,7 +752,7 @@ var genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts2 =
750
752
  var shake128 = /* @__PURE__ */ genShake(31, 168, 16, /* @__PURE__ */ oidNist(11));
751
753
  var shake256 = /* @__PURE__ */ genShake(31, 136, 32, /* @__PURE__ */ oidNist(12));
752
754
 
753
- // node_modules/@noble/curves/abstract/fft.js
755
+ // ../../node_modules/@noble/curves/abstract/fft.js
754
756
  function checkU32(n) {
755
757
  if (!Number.isSafeInteger(n) || n < 0 || n > 4294967295)
756
758
  throw new Error("wrong u32 integer:" + n);
@@ -835,7 +837,7 @@ var FFTCore = (F2, coreOpts) => {
835
837
  };
836
838
  };
837
839
 
838
- // node_modules/@noble/post-quantum/utils.js
840
+ // ../../node_modules/@noble/post-quantum/utils.js
839
841
  var abytesDoc = abytes;
840
842
  var randomBytes2 = randomBytes;
841
843
  function equalBytes(a, b) {
@@ -922,7 +924,7 @@ function getMask(bits) {
922
924
  return bits === 32 ? 4294967295 : ~(-1 << bits) >>> 0;
923
925
  }
924
926
 
925
- // node_modules/@noble/post-quantum/_crystals.js
927
+ // ../../node_modules/@noble/post-quantum/_crystals.js
926
928
  var genCrystals = (opts2) => {
927
929
  const { newPoly, N: N2, Q: Q2, F: F2, ROOT_OF_UNITY: ROOT_OF_UNITY2, brvBits, isKyber } = opts2;
928
930
  const mod2 = (a, modulo = Q2) => {
@@ -1041,7 +1043,7 @@ var createXofShake = (shake) => (seed, blockLen) => {
1041
1043
  };
1042
1044
  var XOF128 = /* @__PURE__ */ createXofShake(shake128);
1043
1045
 
1044
- // node_modules/@noble/post-quantum/ml-kem.js
1046
+ // ../../node_modules/@noble/post-quantum/ml-kem.js
1045
1047
  var N = 256;
1046
1048
  var Q = 3329;
1047
1049
  var F = 3303;
@@ -1323,7 +1325,7 @@ var mk = (params) => createKyber({
1323
1325
  });
1324
1326
  var ml_kem768 = /* @__PURE__ */ (() => mk(PARAMS[768]))();
1325
1327
 
1326
- // node_modules/@noble/curves/node_modules/@noble/hashes/utils.js
1328
+ // ../../node_modules/@noble/curves/node_modules/@noble/hashes/utils.js
1327
1329
  function isBytes2(a) {
1328
1330
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
1329
1331
  }
@@ -1479,7 +1481,7 @@ var oidNist2 = (suffix) => ({
1479
1481
  oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
1480
1482
  });
1481
1483
 
1482
- // node_modules/@noble/curves/node_modules/@noble/hashes/_md.js
1484
+ // ../../node_modules/@noble/curves/node_modules/@noble/hashes/_md.js
1483
1485
  function Chi(a, b, c) {
1484
1486
  return a & b ^ ~a & c;
1485
1487
  }
@@ -1593,7 +1595,7 @@ var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
1593
1595
  1541459225
1594
1596
  ]);
1595
1597
 
1596
- // node_modules/@noble/curves/node_modules/@noble/hashes/sha2.js
1598
+ // ../../node_modules/@noble/curves/node_modules/@noble/hashes/sha2.js
1597
1599
  var SHA256_K = /* @__PURE__ */ Uint32Array.from([
1598
1600
  1116352408,
1599
1601
  1899447441,
@@ -1744,7 +1746,7 @@ var sha256 = /* @__PURE__ */ createHasher2(
1744
1746
  /* @__PURE__ */ oidNist2(1)
1745
1747
  );
1746
1748
 
1747
- // node_modules/@noble/curves/utils.js
1749
+ // ../../node_modules/@noble/curves/utils.js
1748
1750
  var abytes3 = (value, length, title) => abytes2(value, length, title);
1749
1751
  var anumber3 = anumber2;
1750
1752
  var bytesToHex2 = bytesToHex;
@@ -1896,7 +1898,7 @@ function validateObject(object, fields = {}, optFields = {}) {
1896
1898
  iter(optFields, true);
1897
1899
  }
1898
1900
 
1899
- // node_modules/@noble/curves/abstract/modular.js
1901
+ // ../../node_modules/@noble/curves/abstract/modular.js
1900
1902
  var _0n3 = /* @__PURE__ */ BigInt(0);
1901
1903
  var _1n3 = /* @__PURE__ */ BigInt(1);
1902
1904
  var _2n2 = /* @__PURE__ */ BigInt(2);
@@ -2300,7 +2302,7 @@ function mapHashToField(key, fieldOrder, isLE2 = false) {
2300
2302
  return isLE2 ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
2301
2303
  }
2302
2304
 
2303
- // node_modules/@noble/curves/abstract/curve.js
2305
+ // ../../node_modules/@noble/curves/abstract/curve.js
2304
2306
  var _0n4 = /* @__PURE__ */ BigInt(0);
2305
2307
  var _1n4 = /* @__PURE__ */ BigInt(1);
2306
2308
  function negateCt(condition, item) {
@@ -2534,7 +2536,7 @@ function createKeygen(randomSecretKey, getPublicKey) {
2534
2536
  };
2535
2537
  }
2536
2538
 
2537
- // node_modules/@noble/curves/node_modules/@noble/hashes/hmac.js
2539
+ // ../../node_modules/@noble/curves/node_modules/@noble/hashes/hmac.js
2538
2540
  var _HMAC = class {
2539
2541
  oHash;
2540
2542
  iHash;
@@ -2610,7 +2612,7 @@ var hmac = /* @__PURE__ */ (() => {
2610
2612
  return hmac_;
2611
2613
  })();
2612
2614
 
2613
- // node_modules/@noble/curves/abstract/weierstrass.js
2615
+ // ../../node_modules/@noble/curves/abstract/weierstrass.js
2614
2616
  var divNearest = (num, den) => (num + (num >= 0 ? den : -den) / _2n3) / den;
2615
2617
  function _splitEndoScalar(k, basis, n) {
2616
2618
  aInRange("scalar", k, _0n5, n);
@@ -3518,7 +3520,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
3518
3520
  });
3519
3521
  }
3520
3522
 
3521
- // node_modules/@noble/curves/nist.js
3523
+ // ../../node_modules/@noble/curves/nist.js
3522
3524
  var p256_CURVE = /* @__PURE__ */ (() => ({
3523
3525
  p: BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),
3524
3526
  n: BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),
@@ -3701,10 +3703,19 @@ async function combineSharesAndDecrypt(customerShare, custodialShare, chunk, p25
3701
3703
  const ct = base64ToBytes(chunk.encrypted_payload);
3702
3704
  return aesGcmDecrypt(aesKey, iv, ct, tag);
3703
3705
  }
3706
+ function checkV6Metadata(ephemPub, mlkemCt) {
3707
+ if (ephemPub.length !== 33) {
3708
+ throw new Error(`Malformed v6 chunk metadata: ecdh_public_key_hex must be 33 bytes (a compressed P-256 key), got ${ephemPub.length}`);
3709
+ }
3710
+ if (mlkemCt.length !== 1088) {
3711
+ throw new Error(`Malformed v6 chunk metadata: mlkem_ciphertext_hex must be 1088 bytes (an ML-KEM-768 ciphertext), got ${mlkemCt.length}`);
3712
+ }
3713
+ }
3704
3714
  async function combineSharesAndDecryptHybrid(customerShare, custodialShare, chunk) {
3705
3715
  const meta = chunk.encryption_metadata;
3706
3716
  const ephemPub = hexToBytes3(meta.ecdh_public_key_hex);
3707
3717
  const mlkemCt = hexToBytes3(meta.mlkem_ciphertext_hex);
3718
+ checkV6Metadata(ephemPub, mlkemCt);
3708
3719
  const iv = hexToBytes3(meta.iv_hex);
3709
3720
  const tag = hexToBytes3(meta.tag_hex);
3710
3721
  const ct = base64ToBytes(chunk.encrypted_payload);
@@ -3923,6 +3934,23 @@ async function decryptMessage({ message, wrapped, customerShare, recoveryPhrase,
3923
3934
  const pt = await decryptDisclosedChunk(share, custodial, chunk, p256ScalarMul);
3924
3935
  return new TextDecoder().decode(pt);
3925
3936
  }
3937
+ async function mlkemKeyRegistrationMessage(publicKeyHex, mlkemPublicKey) {
3938
+ const h = await sha256Hex(mlkemPublicKey);
3939
+ return new TextEncoder().encode(`enyal-mlkem-key-v1
3940
+ ${String(publicKeyHex).toLowerCase()}
3941
+ ${h}`);
3942
+ }
3943
+ async function mlkemKeyRegistration(keys, customerShare) {
3944
+ const custodial = await decryptCustodialShare(customerShare, keys.customer_wrapped_custodial);
3945
+ const scalar = shamirCombine(customerShare, custodial);
3946
+ const pubHex = bytesToHex3(p256.getPublicKey(scalar, true));
3947
+ if (pubHex !== String(keys.public_key_hex).toLowerCase()) {
3948
+ throw new Error("this share or phrase does not rebuild this account's key \u2014 nothing was sent");
3949
+ }
3950
+ const { publicKey: ek } = ml_kem768.keygen(await deriveMlkemSeed(customerShare));
3951
+ const sig = p256.sign(await mlkemKeyRegistrationMessage(pubHex, ek), scalar, { lowS: true });
3952
+ return { pq_public_key_hex: bytesToHex3(ek), signature_hex: bytesToHex3(sig) };
3953
+ }
3926
3954
 
3927
3955
  // src/enyal.js
3928
3956
  var ENYAL_BASE = "https://api.enyal.ai";
@@ -4009,12 +4037,14 @@ var EnyalSubmodule = class {
4009
4037
  }
4010
4038
  /** 2.1.0: enyal-client.js:483. ENFORCED (disclose_routes.py:274).
4011
4039
  * Content or share proofs: A proof paid for and not delivered is refunded in the same call: the response carries `refunded_joules` (refunds already sent back to your wallet) and `joule_cost` = the price minus it; a refund still in flight completes automatically and is not counted. A failure after the charge is an error and is refunded in full. */
4012
- disclose({ chunkIds, recipientPubkeyHex, purpose, idempotencyKey, retry = true }) {
4040
+ disclose({ chunkIds, recipientPubkeyHex, purpose, idempotencyKey, retry = true, recipientMlkemEkHex }) {
4041
+ const body = { chunk_ids: chunkIds, recipient_pubkey_hex: recipientPubkeyHex, purpose };
4042
+ if (recipientMlkemEkHex != null) body.recipient_mlkem_ek_hex = recipientMlkemEkHex;
4013
4043
  return this._t.request(
4014
4044
  this._base,
4015
4045
  "POST",
4016
4046
  "/api/v1/disclose",
4017
- { body: { chunk_ids: chunkIds, recipient_pubkey_hex: recipientPubkeyHex, purpose }, idempotencyKey, retry }
4047
+ { body, idempotencyKey, retry }
4018
4048
  );
4019
4049
  }
4020
4050
  /** 2.1.0: enyal-client.js:201. ENFORCED (disclose_routes.py:654). */
@@ -4098,6 +4128,23 @@ var EnyalSubmodule = class {
4098
4128
  getMyMessageKeys() {
4099
4129
  return this._t.request(this._base, "GET", "/api/v1/message/my-keys", {});
4100
4130
  }
4131
+ /** P-DAY.160 ML-KEM a3(a), unreleased: give an account whose keys predate ENYAL's post-quantum key (made before 2026-07-10) its
4132
+ * ML-KEM-768 key, from this device: derived from your customer share as ENYAL derives it for newer accounts; only its public half is
4133
+ * sent, signed by your account key. Give customerShare (33 bytes or 66 hex) OR recoveryPhrase (24 words). */
4134
+ async registerMlkemKey({ customerShare, recoveryPhrase } = {}) {
4135
+ const keys = await this.getMyMessageKeys();
4136
+ if (keys.has_pq) return { status: "already_registered", has_pq: true };
4137
+ let share;
4138
+ if (customerShare != null) share = typeof customerShare === "string" ? hexToBytes3(customerShare) : new Uint8Array(customerShare);
4139
+ else if (recoveryPhrase != null) share = mnemonicToCustomerShare(recoveryPhrase);
4140
+ else throw new Error("provide customerShare or recoveryPhrase");
4141
+ return this._t.request(
4142
+ this._base,
4143
+ "POST",
4144
+ "/api/v1/message/my-keys/mlkem",
4145
+ { body: await mlkemKeyRegistration(keys, share) }
4146
+ );
4147
+ }
4101
4148
  /** P-DAY.83 Option C PRE-SEND check: the effective protection a message from
4102
4149
  * this account to `recipientAgentId` would have. Check this BEFORE sending
4103
4150
  * anything you would not want the platform to read. */
@@ -4360,6 +4407,21 @@ var GldaiSubmodule = class {
4360
4407
  if (search) params.search = search;
4361
4408
  return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
4362
4409
  }
4410
+ /** GET /api/v1/signals — the live signal cards (Signal Engine S8), the one read of them; same as the MCP `signals` tool.
4411
+ * Params: kind ("lead_lag" | "network" | "signature", default all three), country (ISO-2), limit (1-50, default 20).
4412
+ * Each card: id, kind, family, title, summary, country, sector, severity, entity_ids, compiled_at, expires_at,
4413
+ * answer_sha256 (the hash of the answer exactly as compiled); once the ranked feed is live, also rank_score with its
4414
+ * parts (precision, lead_weight, recency) and the answer is ordered by it. A type serves cards only while ARMED (its
4415
+ * backtest met the floor); NO TYPE IS ARMED YET, so this answers 0 cards today, which costs nothing (armed_types and
4416
+ * armed_note ride on every answer). Metered per card DELIVERED (200 J a card today; an empty answer is 0 J) against the
4417
+ * CALLING agent's wallet — quote first with billingQuote("/api/v1/signals"); charged_joules + the metering block (file
4418
+ * header). Signals are measured observations with their provenance, never advice. Agent keys only. */
4419
+ signals({ kind, country, limit = 20, idempotencyKey } = {}) {
4420
+ const params = { limit };
4421
+ if (kind) params.kind = kind;
4422
+ if (country) params.country = country;
4423
+ return this._t.request(this._base, "GET", "/api/v1/signals", { params, idempotencyKey });
4424
+ }
4363
4425
  /** GET /api/v1/map.viewport — everything inside a bounding box (THE SCREEN): capped, id-ordered `pins`
4364
4426
  * + `counts_by_type` (counts are the TRUE totals for the whole bbox; pins are a sample). Params:
4365
4427
  * minLat/minLng/maxLat/maxLng (the bbox), entityType (deposit|infrastructure|company|project — default
@@ -4647,6 +4709,8 @@ var JoulepaiSubmodule = class {
4647
4709
  { pathParams: { cur: currency.toUpperCase() } }
4648
4710
  )).joules_per_unit;
4649
4711
  }
4712
+ /** Every spending cap that applies to the wallet, and which one wins: the wallet's own daily_cap / per_transaction_cap / allowed_platforms, `wallet` (binds, can_bind, spent_today,
4713
+ * remaining), `keys` (each agent key's daily_limit, spent_today, remaining, binding_daily_cap) and measure "all_in" (the amount plus the transfer fee, 0.5% rounded up to a whole joule). */
4650
4714
  async getLimits() {
4651
4715
  return this._t.request(
4652
4716
  this._base,
@@ -4655,9 +4719,10 @@ var JoulepaiSubmodule = class {
4655
4719
  { pathParams: { wid: await this._ensureId() } }
4656
4720
  );
4657
4721
  }
4658
- /** Set the wallet's spending limits. SESSION-ONLY — build the Client with your signed-in session (oauthToken: the
4722
+ /** Set the wallet cap (an agent or a human wallet; only its owner). SESSION-ONLY — build the Client with your signed-in session (oauthToken: the
4659
4723
  * 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. */
4724
+ * {"error":"session_required"}, ScopeError). Reading them (getLimits) is unchanged. PUT /wallet/limits replaces the whole
4725
+ * record: a cap you leave out is cleared, so setLimits() with no options removes the wallet cap; 0 is a cap of zero joules, not "no cap". */
4661
4726
  async setLimits({ daily, perTransaction, allowedPlatforms } = {}) {
4662
4727
  const body = { agent_wallet_id: await this._ensureId() };
4663
4728
  if (daily != null) body.daily_cap = daily;
@@ -5026,7 +5091,7 @@ var RareeaiSubmodule = class _RareeaiSubmodule {
5026
5091
  };
5027
5092
 
5028
5093
  // index.js
5029
- var VERSION = "3.0.2";
5094
+ var VERSION = "3.1.0";
5030
5095
  var Client = class {
5031
5096
  /**
5032
5097
  * @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 = "3.0.2";
19
+ export const VERSION = "3.1.0";
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": "3.0.2",
3
+ "version": "3.1.0",
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",
@@ -295,10 +295,26 @@ export async function combineSharesAndDecrypt(customerShare, custodialShare, chu
295
295
  /** v6 HYBRID decrypt (REV20 part-3) — mirror of bsv_memory.decrypt_memory_hybrid.
296
296
  * Classical: shamirCombine -> account priv -> ECDH x = ss_ec. PQ: ML-KEM sk derived
297
297
  * from the customer share -> decapsulate(mlkem_ct) = ss_pq. hybridKDF -> AES-GCM. */
298
+ /**
299
+ * Refuse malformed v6 metadata by name, before either key is used. Without this a wrong length surfaces only at the AES-GCM
300
+ * tag check, as "invalid recovery phrase or share" — the wrong diagnosis. Mirror of @enyalai/sdk and the Python SDKs.
301
+ */
302
+ function checkV6Metadata(ephemPub, mlkemCt) {
303
+ if (ephemPub.length !== 33) {
304
+ throw new Error("Malformed v6 chunk metadata: ecdh_public_key_hex must be 33 bytes (a compressed P-256 key), " +
305
+ `got ${ephemPub.length}`);
306
+ }
307
+ if (mlkemCt.length !== 1088) {
308
+ throw new Error("Malformed v6 chunk metadata: mlkem_ciphertext_hex must be 1088 bytes (an ML-KEM-768 ciphertext), " +
309
+ `got ${mlkemCt.length}`);
310
+ }
311
+ }
312
+
298
313
  export async function combineSharesAndDecryptHybrid(customerShare, custodialShare, chunk) {
299
314
  const meta = chunk.encryption_metadata;
300
315
  const ephemPub = hexToBytes(meta.ecdh_public_key_hex);
301
316
  const mlkemCt = hexToBytes(meta.mlkem_ciphertext_hex);
317
+ checkV6Metadata(ephemPub, mlkemCt);
302
318
  const iv = hexToBytes(meta.iv_hex);
303
319
  const tag = hexToBytes(meta.tag_hex);
304
320
  const ct = base64ToBytes(chunk.encrypted_payload);
@@ -662,6 +678,33 @@ export async function decryptMessage({ message, wrapped, customerShare, recovery
662
678
  return new TextDecoder().decode(pt);
663
679
  }
664
680
 
681
+ /**
682
+ * P-DAY.160 ML-KEM a3(a): the bytes the account key signs to register its ML-KEM key — the same bytes ENYAL's
683
+ * POST /message/my-keys/mlkem checks (and @enyalai/sdk's): "enyal-mlkem-key-v1", the account public key (compressed, lower-case hex)
684
+ * and SHA-256(ML-KEM public key) hex, newline-separated.
685
+ */
686
+ export async function mlkemKeyRegistrationMessage(publicKeyHex, mlkemPublicKey) {
687
+ const h = await sha256Hex(mlkemPublicKey);
688
+ return new TextEncoder().encode(`enyal-mlkem-key-v1\n${String(publicKeyHex).toLowerCase()}\n${h}`);
689
+ }
690
+
691
+ /**
692
+ * P-DAY.160 ML-KEM a3(a): the body for POST /message/my-keys/mlkem, made on this device. `keys` is GET /message/my-keys. The ML-KEM
693
+ * key derives from the customer share as ENYAL derives it at account creation; the signature is by the account key, rebuilt here from
694
+ * the share and the customer-wrapped custodial share. A wrong share throws before anything is built.
695
+ */
696
+ export async function mlkemKeyRegistration(keys, customerShare) {
697
+ const custodial = await decryptCustodialShare(customerShare, keys.customer_wrapped_custodial);
698
+ const scalar = shamirCombine(customerShare, custodial);
699
+ const pubHex = bytesToHex(p256.getPublicKey(scalar, true));
700
+ if (pubHex !== String(keys.public_key_hex).toLowerCase()) {
701
+ throw new Error("this share or phrase does not rebuild this account's key — nothing was sent");
702
+ }
703
+ const { publicKey: ek } = ml_kem768.keygen(await deriveMlkemSeed(customerShare));
704
+ const sig = p256.sign(await mlkemKeyRegistrationMessage(pubHex, ek), scalar, { lowS: true }); // SHA-256 prehash, 64-byte r||s
705
+ return { pq_public_key_hex: bytesToHex(ek), signature_hex: bytesToHex(sig) };
706
+ }
707
+
665
708
  // REV20 part-3 v6 (2026-07-10): export pure helpers for the interop KAT + stage-3 browser UI
666
709
  // (parity with @enyalai/sdk enyal-client.js bottom export block).
667
710
  export { shamirCombine, hexToBytes, bytesToHex };
package/src/enyal.js CHANGED
@@ -76,9 +76,12 @@ export class EnyalSubmodule {
76
76
 
77
77
  /** 2.1.0: enyal-client.js:483. ENFORCED (disclose_routes.py:274).
78
78
  * Content or share proofs: A proof paid for and not delivered is refunded in the same call: the response carries `refunded_joules` (refunds already sent back to your wallet) and `joule_cost` = the price minus it; a refund still in flight completes automatically and is not counted. A failure after the charge is an error and is refunded in full. */
79
- disclose({ chunkIds, recipientPubkeyHex, purpose, idempotencyKey, retry = true }) {
79
+ disclose({ chunkIds, recipientPubkeyHex, purpose, idempotencyKey, retry = true, recipientMlkemEkHex }) {
80
+ // P-DAY.160 a3(b): recipientMlkemEkHex (the recipient's ML-KEM-768 key) → each chunk comes back payload_version 6
81
+ const body = { chunk_ids: chunkIds, recipient_pubkey_hex: recipientPubkeyHex, purpose };
82
+ if (recipientMlkemEkHex != null) body.recipient_mlkem_ek_hex = recipientMlkemEkHex;
80
83
  return this._t.request(this._base, "POST", "/api/v1/disclose",
81
- { body: { chunk_ids: chunkIds, recipient_pubkey_hex: recipientPubkeyHex, purpose }, idempotencyKey, retry });
84
+ { body, idempotencyKey, retry });
82
85
  }
83
86
 
84
87
  /** 2.1.0: enyal-client.js:201. ENFORCED (disclose_routes.py:654). */
@@ -142,6 +145,20 @@ export class EnyalSubmodule {
142
145
  return this._t.request(this._base, "GET", "/api/v1/message/my-keys", {});
143
146
  }
144
147
 
148
+ /** P-DAY.160 ML-KEM a3(a), unreleased: give an account whose keys predate ENYAL's post-quantum key (made before 2026-07-10) its
149
+ * ML-KEM-768 key, from this device: derived from your customer share as ENYAL derives it for newer accounts; only its public half is
150
+ * sent, signed by your account key. Give customerShare (33 bytes or 66 hex) OR recoveryPhrase (24 words). */
151
+ async registerMlkemKey({ customerShare, recoveryPhrase } = {}) {
152
+ const keys = await this.getMyMessageKeys();
153
+ if (keys.has_pq) return { status: "already_registered", has_pq: true };
154
+ let share;
155
+ if (customerShare != null) share = typeof customerShare === "string" ? cryptoNs.hexToBytes(customerShare) : new Uint8Array(customerShare);
156
+ else if (recoveryPhrase != null) share = cryptoNs.mnemonicToCustomerShare(recoveryPhrase);
157
+ else throw new Error("provide customerShare or recoveryPhrase");
158
+ return this._t.request(this._base, "POST", "/api/v1/message/my-keys/mlkem",
159
+ { body: await cryptoNs.mlkemKeyRegistration(keys, share) });
160
+ }
161
+
145
162
  /** P-DAY.83 Option C PRE-SEND check: the effective protection a message from
146
163
  * this account to `recipientAgentId` would have. Check this BEFORE sending
147
164
  * anything you would not want the platform to read. */
package/src/gldai.js CHANGED
@@ -144,6 +144,21 @@ export class GldaiSubmodule {
144
144
  if (search) params.search = search;
145
145
  return this._t.request(this._base, "GET", "/api/v1/relationships", { params, idempotencyKey });
146
146
  }
147
+ /** GET /api/v1/signals — the live signal cards (Signal Engine S8), the one read of them; same as the MCP `signals` tool.
148
+ * Params: kind ("lead_lag" | "network" | "signature", default all three), country (ISO-2), limit (1-50, default 20).
149
+ * Each card: id, kind, family, title, summary, country, sector, severity, entity_ids, compiled_at, expires_at,
150
+ * answer_sha256 (the hash of the answer exactly as compiled); once the ranked feed is live, also rank_score with its
151
+ * parts (precision, lead_weight, recency) and the answer is ordered by it. A type serves cards only while ARMED (its
152
+ * backtest met the floor); NO TYPE IS ARMED YET, so this answers 0 cards today, which costs nothing (armed_types and
153
+ * armed_note ride on every answer). Metered per card DELIVERED (200 J a card today; an empty answer is 0 J) against the
154
+ * CALLING agent's wallet — quote first with billingQuote("/api/v1/signals"); charged_joules + the metering block (file
155
+ * header). Signals are measured observations with their provenance, never advice. Agent keys only. */
156
+ signals({ kind, country, limit = 20, idempotencyKey } = {}) {
157
+ const params = { limit };
158
+ if (kind) params.kind = kind;
159
+ if (country) params.country = country;
160
+ return this._t.request(this._base, "GET", "/api/v1/signals", { params, idempotencyKey });
161
+ }
147
162
  /** GET /api/v1/map.viewport — everything inside a bounding box (THE SCREEN): capped, id-ordered `pins`
148
163
  * + `counts_by_type` (counts are the TRUE totals for the whole bbox; pins are a sample). Params:
149
164
  * minLat/minLng/maxLat/maxLng (the bbox), entityType (deposit|infrastructure|company|project — default
package/src/joulepai.js CHANGED
@@ -140,14 +140,17 @@ export class JoulepaiSubmodule {
140
140
  { pathParams: { cur: currency.toUpperCase() } })).joules_per_unit;
141
141
  }
142
142
 
143
+ /** Every spending cap that applies to the wallet, and which one wins: the wallet's own daily_cap / per_transaction_cap / allowed_platforms, `wallet` (binds, can_bind, spent_today,
144
+ * remaining), `keys` (each agent key's daily_limit, spent_today, remaining, binding_daily_cap) and measure "all_in" (the amount plus the transfer fee, 0.5% rounded up to a whole joule). */
143
145
  async getLimits() {
144
146
  return this._t.request(this._base, "GET", "/wallet/limits/{wid}",
145
147
  { pathParams: { wid: await this._ensureId() } });
146
148
  }
147
149
 
148
- /** Set the wallet's spending limits. SESSION-ONLY — build the Client with your signed-in session (oauthToken: the
150
+ /** Set the wallet cap (an agent or a human wallet; only its owner). SESSION-ONLY — build the Client with your signed-in session (oauthToken: the
149
151
  * ENYAL session from sign-in, or joulepai.ai's own session JWT), NOT an API key or OAuth token (refused 403
150
- * {"error":"session_required"}, ScopeError). Reading them (getLimits) is unchanged. PUT /wallet/limits. */
152
+ * {"error":"session_required"}, ScopeError). Reading them (getLimits) is unchanged. PUT /wallet/limits replaces the whole
153
+ * record: a cap you leave out is cleared, so setLimits() with no options removes the wallet cap; 0 is a cap of zero joules, not "no cap". */
151
154
  async setLimits({ daily, perTransaction, allowedPlatforms } = {}) {
152
155
  const body = { agent_wallet_id: await this._ensureId() };
153
156
  if (daily != null) body.daily_cap = daily;