@wishknish/knishio-client-ts 0.9.8 → 1.0.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/dist/index.cjs +211 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -34
- package/dist/index.d.ts +40 -34
- package/dist/index.iife.js +212 -48
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +212 -49
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/AuthToken.ts +47 -25
- package/src/KnishIOClient.ts +40 -12
- package/src/core/Molecule.ts +17 -7
- package/src/core/Wallet.ts +161 -32
- package/src/index.ts +2 -2
- package/src/libraries/GraphQLClient.ts +2 -2
- package/src/schemas/index.ts +2 -1
- package/src/types/crypto.ts +9 -4
- package/src/validation/schemas.ts +2 -1
package/dist/index.iife.js
CHANGED
|
@@ -42562,8 +42562,14 @@ ${operationTypes.join("\n")}
|
|
|
42562
42562
|
...params
|
|
42563
42563
|
});
|
|
42564
42564
|
var ml_kem768 = /* @__PURE__ */ (() => mk(PARAMS[768]))();
|
|
42565
|
+
var ml_kem1024 = /* @__PURE__ */ (() => mk(PARAMS[1024]))();
|
|
42565
42566
|
|
|
42566
42567
|
// src/core/Wallet.ts
|
|
42568
|
+
var ML_KEM_PARAMS = {
|
|
42569
|
+
1024: { kem: ml_kem1024, pkBytes: 1568, skBytes: 3168, ctBytes: 1568 },
|
|
42570
|
+
768: { kem: ml_kem768, pkBytes: 1184, skBytes: 2400, ctBytes: 1088 }
|
|
42571
|
+
};
|
|
42572
|
+
var DEFAULT_ML_KEM_PARAMETER_SET = 1024;
|
|
42567
42573
|
var Wallet = class _Wallet {
|
|
42568
42574
|
token;
|
|
42569
42575
|
balance;
|
|
@@ -42578,6 +42584,7 @@ ${operationTypes.join("\n")}
|
|
|
42578
42584
|
tokenUnits;
|
|
42579
42585
|
tradeRates;
|
|
42580
42586
|
molecules;
|
|
42587
|
+
mlKemParameterSet;
|
|
42581
42588
|
// Token metadata (populated from query responses)
|
|
42582
42589
|
tokenName;
|
|
42583
42590
|
tokenAmount;
|
|
@@ -42591,8 +42598,14 @@ ${operationTypes.join("\n")}
|
|
|
42591
42598
|
address = null,
|
|
42592
42599
|
position = null,
|
|
42593
42600
|
batchId = null,
|
|
42594
|
-
characters = null
|
|
42601
|
+
characters = null,
|
|
42602
|
+
mlKemParameterSet = DEFAULT_ML_KEM_PARAMETER_SET
|
|
42595
42603
|
} = {}) {
|
|
42604
|
+
const paramSetNum = Number(mlKemParameterSet);
|
|
42605
|
+
if (!ML_KEM_PARAMS[paramSetNum]) {
|
|
42606
|
+
throw new Error(`KnishIO: unsupported ML-KEM parameter set ${mlKemParameterSet}; expected 1024 or 768.`);
|
|
42607
|
+
}
|
|
42608
|
+
this.mlKemParameterSet = paramSetNum;
|
|
42596
42609
|
this.token = token;
|
|
42597
42610
|
this.balance = "0";
|
|
42598
42611
|
this.molecules = {};
|
|
@@ -42628,7 +42641,8 @@ ${operationTypes.join("\n")}
|
|
|
42628
42641
|
bundle = null,
|
|
42629
42642
|
token = "USER",
|
|
42630
42643
|
batchId = null,
|
|
42631
|
-
characters = null
|
|
42644
|
+
characters = null,
|
|
42645
|
+
mlKemParameterSet = DEFAULT_ML_KEM_PARAMETER_SET
|
|
42632
42646
|
}) {
|
|
42633
42647
|
let position = null;
|
|
42634
42648
|
if (!secret && !bundle) {
|
|
@@ -42644,7 +42658,8 @@ ${operationTypes.join("\n")}
|
|
|
42644
42658
|
token,
|
|
42645
42659
|
position,
|
|
42646
42660
|
batchId,
|
|
42647
|
-
characters
|
|
42661
|
+
characters,
|
|
42662
|
+
mlKemParameterSet
|
|
42648
42663
|
});
|
|
42649
42664
|
}
|
|
42650
42665
|
/**
|
|
@@ -42803,20 +42818,80 @@ ${operationTypes.join("\n")}
|
|
|
42803
42818
|
return (typeof this.position === "undefined" || this.position === null) && (typeof this.address === "undefined" || this.address === null);
|
|
42804
42819
|
}
|
|
42805
42820
|
// =============================================================================
|
|
42806
|
-
// POST-QUANTUM CRYPTOGRAPHY - ML-
|
|
42821
|
+
// POST-QUANTUM CRYPTOGRAPHY - ML-KEM INTEGRATION
|
|
42807
42822
|
// =============================================================================
|
|
42808
42823
|
/**
|
|
42809
|
-
*
|
|
42824
|
+
* Derive an ML-KEM keypair for an arbitrary parameter set from the wallet's key seed,
|
|
42825
|
+
* without mutating the wallet. The 64-byte `d‖z` seed takes no parameter-set input — only
|
|
42826
|
+
* the final `keygen` call differs — so one KnishIO wallet owns both an ML-KEM-768 and an
|
|
42827
|
+
* ML-KEM-1024 identity and either can be reconstructed on demand.
|
|
42828
|
+
*
|
|
42829
|
+
* Returns `null` when the wallet holds no key — a secret-less wallet, which is what a molecule
|
|
42830
|
+
* deserializer builds for validation context. `generateSecret(null, …)` does NOT throw, so
|
|
42831
|
+
* without this the wallet would derive a plausible-looking identity from a bogus seed and fail
|
|
42832
|
+
* three layers down at AES-GCM instead of at the missing key. The guard lives here rather than
|
|
42833
|
+
* at each call site so a new caller cannot miss it.
|
|
42834
|
+
*
|
|
42835
|
+
* @param parameterSet - 1024 or 768
|
|
42810
42836
|
*/
|
|
42811
|
-
|
|
42837
|
+
deriveMlKemKeypair(parameterSet) {
|
|
42838
|
+
const params = ML_KEM_PARAMS[parameterSet];
|
|
42839
|
+
if (!params) {
|
|
42840
|
+
throw new Error(`KnishIO: unsupported ML-KEM parameter set ${parameterSet}; expected 1024 or 768.`);
|
|
42841
|
+
}
|
|
42842
|
+
if (!this.key) {
|
|
42843
|
+
return null;
|
|
42844
|
+
}
|
|
42812
42845
|
const seedHex = generateSecret(this.key, 128);
|
|
42813
42846
|
const seed = new Uint8Array(64);
|
|
42814
42847
|
for (let i4 = 0; i4 < 64; i4++) {
|
|
42815
42848
|
seed[i4] = parseInt(seedHex.substr(i4 * 2, 2), 16);
|
|
42816
42849
|
}
|
|
42817
|
-
const { publicKey, secretKey } =
|
|
42818
|
-
|
|
42819
|
-
|
|
42850
|
+
const { publicKey, secretKey } = params.kem.keygen(seed);
|
|
42851
|
+
return {
|
|
42852
|
+
pubkey: this.serializeKey(publicKey),
|
|
42853
|
+
privkey: secretKey,
|
|
42854
|
+
params
|
|
42855
|
+
};
|
|
42856
|
+
}
|
|
42857
|
+
/**
|
|
42858
|
+
* ML-KEM parameter set implied by a serialized public key's raw byte length. FIPS 203's key
|
|
42859
|
+
* lengths are disjoint (1568 bytes → ML-KEM-1024, 1184 bytes → ML-KEM-768), so a stored peer
|
|
42860
|
+
* key recovers the parameter set of the session it belongs to without a wire-format change.
|
|
42861
|
+
* Used by AuthToken.restore to resolve a snapshot that predates the field.
|
|
42862
|
+
*
|
|
42863
|
+
* @param pubkey - Base64-serialized ML-KEM public key
|
|
42864
|
+
* @return 1024, 768, or null when the length matches neither
|
|
42865
|
+
*/
|
|
42866
|
+
static mlKemParameterSetFromPubkey(pubkey) {
|
|
42867
|
+
if (!pubkey) {
|
|
42868
|
+
return null;
|
|
42869
|
+
}
|
|
42870
|
+
let byteLength;
|
|
42871
|
+
try {
|
|
42872
|
+
byteLength = typeof Buffer !== "undefined" ? Buffer.from(pubkey, "base64").length : atob(pubkey).length;
|
|
42873
|
+
} catch {
|
|
42874
|
+
return null;
|
|
42875
|
+
}
|
|
42876
|
+
if (byteLength === ML_KEM_PARAMS[1024].pkBytes) {
|
|
42877
|
+
return 1024;
|
|
42878
|
+
}
|
|
42879
|
+
if (byteLength === ML_KEM_PARAMS[768].pkBytes) {
|
|
42880
|
+
return 768;
|
|
42881
|
+
}
|
|
42882
|
+
return null;
|
|
42883
|
+
}
|
|
42884
|
+
/**
|
|
42885
|
+
* Initializes the ML-KEM key pair (matches JavaScript SDK exactly). Only ever reached from the
|
|
42886
|
+
* constructor's `secret` branch, so the derivation cannot come back empty here.
|
|
42887
|
+
*/
|
|
42888
|
+
initializeMLKEM() {
|
|
42889
|
+
const derived = this.deriveMlKemKeypair(this.mlKemParameterSet);
|
|
42890
|
+
if (!derived) {
|
|
42891
|
+
return;
|
|
42892
|
+
}
|
|
42893
|
+
this.pubkey = derived.pubkey;
|
|
42894
|
+
this.privkey = derived.privkey;
|
|
42820
42895
|
}
|
|
42821
42896
|
// =============================================================================
|
|
42822
42897
|
// HIGH-LEVEL MESSAGE ENCRYPTION (JavaScript SDK Compatibility)
|
|
@@ -42825,13 +42900,13 @@ ${operationTypes.join("\n")}
|
|
|
42825
42900
|
const messageString = JSON.stringify(message);
|
|
42826
42901
|
const messageUint8 = new TextEncoder().encode(messageString);
|
|
42827
42902
|
const deserializedPubkey = this.deserializeKey(recipientPubkey);
|
|
42828
|
-
const
|
|
42829
|
-
if (deserializedPubkey.length !==
|
|
42903
|
+
const params = ML_KEM_PARAMS[this.mlKemParameterSet];
|
|
42904
|
+
if (deserializedPubkey.length !== params.pkBytes) {
|
|
42830
42905
|
throw new Error(
|
|
42831
|
-
`KnishIO: cannot ML-KEM-encrypt \u2014 recipient public key is ${deserializedPubkey.length} bytes, expected ${
|
|
42906
|
+
`KnishIO: cannot ML-KEM-encrypt \u2014 recipient public key is ${deserializedPubkey.length} bytes, expected ${params.pkBytes} (ML-KEM-${this.mlKemParameterSet}). The peer is not running ML-KEM-${this.mlKemParameterSet}; upgrade the peer, or step this client back to the other parameter set.`
|
|
42832
42907
|
);
|
|
42833
42908
|
}
|
|
42834
|
-
const { cipherText, sharedSecret } =
|
|
42909
|
+
const { cipherText, sharedSecret } = params.kem.encapsulate(deserializedPubkey);
|
|
42835
42910
|
const encryptedMessage = await this.encryptWithSharedSecret(messageUint8, sharedSecret);
|
|
42836
42911
|
return {
|
|
42837
42912
|
cipherText: this.serializeKey(cipherText),
|
|
@@ -42843,15 +42918,37 @@ ${operationTypes.join("\n")}
|
|
|
42843
42918
|
return decryptedString === null ? null : JSON.parse(decryptedString);
|
|
42844
42919
|
}
|
|
42845
42920
|
/**
|
|
42846
|
-
* ML-
|
|
42921
|
+
* ML-KEM decapsulate + AES-256-GCM decrypt → the RAW decrypted UTF-8 string (no JSON.parse).
|
|
42847
42922
|
* Shared by {@link decryptMessage} (which JSON.parses the result) and the PQ CipherHash transport
|
|
42848
|
-
* ({@link
|
|
42923
|
+
* ({@link decryptMyMessageML}, which needs the raw response JSON text). PQ-transport Phase E.
|
|
42849
42924
|
*/
|
|
42850
42925
|
async _mlkemDecryptToString(encryptedData) {
|
|
42851
42926
|
const { cipherText, encryptedMessage } = encryptedData;
|
|
42927
|
+
const configuredParams = ML_KEM_PARAMS[this.mlKemParameterSet];
|
|
42928
|
+
const otherSet = this.mlKemParameterSet === 1024 ? 768 : 1024;
|
|
42929
|
+
const deserializedCipherText = this.deserializeKey(cipherText);
|
|
42930
|
+
let params = configuredParams;
|
|
42931
|
+
let decapsPrivkey = this.privkey;
|
|
42932
|
+
if (deserializedCipherText.length !== configuredParams.ctBytes) {
|
|
42933
|
+
if (deserializedCipherText.length !== ML_KEM_PARAMS[otherSet].ctBytes) {
|
|
42934
|
+
console.error(
|
|
42935
|
+
`Wallet::decryptMessage() - Ciphertext length mismatch: got ${deserializedCipherText.length}, expected ${configuredParams.ctBytes}`
|
|
42936
|
+
);
|
|
42937
|
+
return null;
|
|
42938
|
+
}
|
|
42939
|
+
const derived = this.deriveMlKemKeypair(otherSet);
|
|
42940
|
+
if (!derived) {
|
|
42941
|
+
console.error(
|
|
42942
|
+
`Wallet::decryptMessage() - cannot derive the ML-KEM-${otherSet} identity: wallet has no key`
|
|
42943
|
+
);
|
|
42944
|
+
return null;
|
|
42945
|
+
}
|
|
42946
|
+
params = derived.params;
|
|
42947
|
+
decapsPrivkey = derived.privkey;
|
|
42948
|
+
}
|
|
42852
42949
|
let sharedSecret;
|
|
42853
42950
|
try {
|
|
42854
|
-
sharedSecret =
|
|
42951
|
+
sharedSecret = params.kem.decapsulate(deserializedCipherText, decapsPrivkey);
|
|
42855
42952
|
} catch (e4) {
|
|
42856
42953
|
console.error("Wallet::decryptMessage() - Decapsulation failed", e4);
|
|
42857
42954
|
console.info("Wallet::decryptMessage() - my public key", this.pubkey);
|
|
@@ -42901,11 +42998,11 @@ ${operationTypes.join("\n")}
|
|
|
42901
42998
|
return this.serializeKey(bytes);
|
|
42902
42999
|
}
|
|
42903
43000
|
/**
|
|
42904
|
-
* Post-quantum (ML-
|
|
43001
|
+
* Post-quantum (ML-KEM) CipherHash request envelope: a stringified single-recipient map
|
|
42905
43002
|
* `{ "<hashShare(recipientPubkey)>": {cipherText, encryptedMessage} }` (object-valued, via
|
|
42906
43003
|
* {@link encryptMessage}). Matches the Rust validator's CipherHash handler. PQ-transport Phase E.
|
|
42907
43004
|
*/
|
|
42908
|
-
async
|
|
43005
|
+
async encryptStringML(message, recipientPubkey) {
|
|
42909
43006
|
const envelope = await this.encryptMessage(message, recipientPubkey);
|
|
42910
43007
|
return JSON.stringify({ [this.hashShare(recipientPubkey)]: envelope });
|
|
42911
43008
|
}
|
|
@@ -42913,9 +43010,21 @@ ${operationTypes.join("\n")}
|
|
|
42913
43010
|
* Decrypt a CipherHash response map addressed to THIS wallet's ML-KEM pubkey
|
|
42914
43011
|
* (`hashShare(this.pubkey)`) → the RAW decrypted GraphQL response JSON text (NOT JSON.parsed;
|
|
42915
43012
|
* it replaces the HTTP response body for the normal parser). `null` if no entry / decrypt fails.
|
|
43013
|
+
*
|
|
43014
|
+
* A pre-bump peer addressed its envelope to `hashShare(our_768_pubkey)`, which a wallet
|
|
43015
|
+
* configured at ML-KEM-1024 would never find — so the other identity's share is tried too.
|
|
43016
|
+
* Without this, the permissive length dispatch in {@link _mlkemDecryptToString} is
|
|
43017
|
+
* unreachable on the transport path.
|
|
42916
43018
|
*/
|
|
42917
|
-
async
|
|
42918
|
-
|
|
43019
|
+
async decryptMyMessageML(map3) {
|
|
43020
|
+
let envelope = map3[this.hashShare(this.pubkey)];
|
|
43021
|
+
if (!envelope) {
|
|
43022
|
+
const otherSet = this.mlKemParameterSet === 1024 ? 768 : 1024;
|
|
43023
|
+
const other = this.deriveMlKemKeypair(otherSet);
|
|
43024
|
+
if (other) {
|
|
43025
|
+
envelope = map3[this.hashShare(other.pubkey)];
|
|
43026
|
+
}
|
|
43027
|
+
}
|
|
42919
43028
|
if (!envelope) {
|
|
42920
43029
|
return null;
|
|
42921
43030
|
}
|
|
@@ -43072,7 +43181,8 @@ ${operationTypes.join("\n")}
|
|
|
43072
43181
|
serverSdkVersion: external_exports.number().int().min(1).optional(),
|
|
43073
43182
|
logging: external_exports.boolean().optional(),
|
|
43074
43183
|
defaultRequestPolicy: external_exports.enum(["cache-first", "cache-only", "network-only", "cache-and-network"]).nullable().optional(),
|
|
43075
|
-
secretStorage: external_exports.unknown().optional()
|
|
43184
|
+
secretStorage: external_exports.unknown().optional(),
|
|
43185
|
+
mlKemParameterSet: external_exports.union([external_exports.literal(1024), external_exports.literal(768)]).optional()
|
|
43076
43186
|
}).strict();
|
|
43077
43187
|
external_exports.object({
|
|
43078
43188
|
token: external_exports.string().min(1, "Auth token cannot be empty"),
|
|
@@ -44162,6 +44272,7 @@ ${operationTypes.join("\n")}
|
|
|
44162
44272
|
continuIdPosition;
|
|
44163
44273
|
parentHashes;
|
|
44164
44274
|
local;
|
|
44275
|
+
mlKemParameterSet = 1024;
|
|
44165
44276
|
/**
|
|
44166
44277
|
* Create new Molecule instance
|
|
44167
44278
|
* Matches JavaScript SDK constructor signature
|
|
@@ -44173,7 +44284,8 @@ ${operationTypes.join("\n")}
|
|
|
44173
44284
|
remainderWallet = null,
|
|
44174
44285
|
cellSlug = null,
|
|
44175
44286
|
version: version3 = null,
|
|
44176
|
-
continuIdPosition = null
|
|
44287
|
+
continuIdPosition = null,
|
|
44288
|
+
mlKemParameterSet = null
|
|
44177
44289
|
} = {}) {
|
|
44178
44290
|
this.status = null;
|
|
44179
44291
|
this.molecularHash = null;
|
|
@@ -44185,6 +44297,7 @@ ${operationTypes.join("\n")}
|
|
|
44185
44297
|
this.continuIdPosition = continuIdPosition;
|
|
44186
44298
|
this.atoms = [];
|
|
44187
44299
|
this.parentHashes = [];
|
|
44300
|
+
this.mlKemParameterSet = mlKemParameterSet || sourceWallet?.mlKemParameterSet || 1024;
|
|
44188
44301
|
const versionRegistry = versions_default;
|
|
44189
44302
|
if (version3 !== null && Object.prototype.hasOwnProperty.call(versionRegistry, version3)) {
|
|
44190
44303
|
this.version = String(version3);
|
|
@@ -44195,7 +44308,8 @@ ${operationTypes.join("\n")}
|
|
|
44195
44308
|
bundle,
|
|
44196
44309
|
token: sourceWallet.token,
|
|
44197
44310
|
batchId: sourceWallet.batchId,
|
|
44198
|
-
characters: sourceWallet.characters
|
|
44311
|
+
characters: sourceWallet.characters,
|
|
44312
|
+
mlKemParameterSet: this.mlKemParameterSet
|
|
44199
44313
|
});
|
|
44200
44314
|
} else {
|
|
44201
44315
|
this.remainderWallet = null;
|
|
@@ -44256,7 +44370,8 @@ ${operationTypes.join("\n")}
|
|
|
44256
44370
|
if (!this.remainderWallet || this.remainderWallet.token !== "USER") {
|
|
44257
44371
|
this.remainderWallet = Wallet.create({
|
|
44258
44372
|
secret: this.secret,
|
|
44259
|
-
bundle: this.bundle
|
|
44373
|
+
bundle: this.bundle,
|
|
44374
|
+
mlKemParameterSet: this.mlKemParameterSet
|
|
44260
44375
|
});
|
|
44261
44376
|
}
|
|
44262
44377
|
const continuIdMeta = {};
|
|
@@ -44643,7 +44758,8 @@ ${operationTypes.join("\n")}
|
|
|
44643
44758
|
}
|
|
44644
44759
|
const burnWallet = new Wallet({
|
|
44645
44760
|
bundle: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
44646
|
-
token: this.sourceWallet.token
|
|
44761
|
+
token: this.sourceWallet.token,
|
|
44762
|
+
mlKemParameterSet: this.mlKemParameterSet
|
|
44647
44763
|
});
|
|
44648
44764
|
this.addAtom(Atom.create({
|
|
44649
44765
|
isotope: "V",
|
|
@@ -44915,7 +45031,8 @@ ${operationTypes.join("\n")}
|
|
|
44915
45031
|
position: data.sourceWallet.position,
|
|
44916
45032
|
bundle: data.sourceWallet.bundle,
|
|
44917
45033
|
batchId: data.sourceWallet.batchId,
|
|
44918
|
-
characters: data.sourceWallet.characters
|
|
45034
|
+
characters: data.sourceWallet.characters,
|
|
45035
|
+
mlKemParameterSet: molecule.mlKemParameterSet
|
|
44919
45036
|
});
|
|
44920
45037
|
molecule.sourceWallet.balance = String(data.sourceWallet.balance != null ? data.sourceWallet.balance : 0);
|
|
44921
45038
|
molecule.sourceWallet.address = data.sourceWallet.address;
|
|
@@ -44933,7 +45050,8 @@ ${operationTypes.join("\n")}
|
|
|
44933
45050
|
position: data.remainderWallet.position,
|
|
44934
45051
|
bundle: data.remainderWallet.bundle,
|
|
44935
45052
|
batchId: data.remainderWallet.batchId,
|
|
44936
|
-
characters: data.remainderWallet.characters
|
|
45053
|
+
characters: data.remainderWallet.characters,
|
|
45054
|
+
mlKemParameterSet: molecule.mlKemParameterSet
|
|
44937
45055
|
});
|
|
44938
45056
|
molecule.remainderWallet.balance = String(data.remainderWallet.balance != null ? data.remainderWallet.balance : 0);
|
|
44939
45057
|
molecule.remainderWallet.address = data.remainderWallet.address;
|
|
@@ -45031,7 +45149,8 @@ ${operationTypes.join("\n")}
|
|
|
45031
45149
|
secret: this.secret,
|
|
45032
45150
|
bundle: this.bundle,
|
|
45033
45151
|
token: this.sourceWallet.token,
|
|
45034
|
-
batchId: this.sourceWallet.batchId
|
|
45152
|
+
batchId: this.sourceWallet.batchId,
|
|
45153
|
+
mlKemParameterSet: this.mlKemParameterSet
|
|
45035
45154
|
});
|
|
45036
45155
|
if (tradeRates) {
|
|
45037
45156
|
bufferWallet.tradeRates = tradeRates;
|
|
@@ -47728,7 +47847,7 @@ ${operationTypes.join("\n")}
|
|
|
47728
47847
|
let encryptedRequest = false;
|
|
47729
47848
|
let requestInit = init;
|
|
47730
47849
|
if (wallet && serverPubkey && init && typeof init.body === "string" && this.shouldEncrypt(init.body)) {
|
|
47731
|
-
const hashVar = await wallet.
|
|
47850
|
+
const hashVar = await wallet.encryptStringML(init.body, serverPubkey);
|
|
47732
47851
|
requestInit = { ...init, body: JSON.stringify({ query: CIPHER_HASH_QUERY, variables: { Hash: hashVar } }) };
|
|
47733
47852
|
encryptedRequest = true;
|
|
47734
47853
|
}
|
|
@@ -47748,7 +47867,7 @@ ${operationTypes.join("\n")}
|
|
|
47748
47867
|
if (typeof hash2 !== "string") {
|
|
47749
47868
|
return new Response(text, init2);
|
|
47750
47869
|
}
|
|
47751
|
-
const decrypted = await wallet.
|
|
47870
|
+
const decrypted = await wallet.decryptMyMessageML(JSON.parse(hash2));
|
|
47752
47871
|
return new Response(decrypted != null ? decrypted : text, init2);
|
|
47753
47872
|
}
|
|
47754
47873
|
setAuthData({
|
|
@@ -47917,6 +48036,22 @@ ${operationTypes.join("\n")}
|
|
|
47917
48036
|
authToken.setWallet(wallet);
|
|
47918
48037
|
return authToken;
|
|
47919
48038
|
}
|
|
48039
|
+
/**
|
|
48040
|
+
* ML-KEM parameter set a restored session must use, resolved in three tiers:
|
|
48041
|
+
* an explicit snapshot field, then the stored validator key's length, then ML-KEM-768.
|
|
48042
|
+
*
|
|
48043
|
+
* The final tier is deliberately NOT the constructor default. A snapshot with neither an
|
|
48044
|
+
* explicit field nor a recognisable key can only have come from a pre-bump build, and every
|
|
48045
|
+
* pre-bump build was 768-only — defaulting to 1024 would make the restored wallet advertise
|
|
48046
|
+
* a public key the validator never recorded for that token.
|
|
48047
|
+
*/
|
|
48048
|
+
static resolveMlKemParameterSet(snapshot) {
|
|
48049
|
+
const explicit = snapshot.wallet?.mlKemParameterSet;
|
|
48050
|
+
if (explicit) {
|
|
48051
|
+
return Number(explicit) === 768 ? 768 : 1024;
|
|
48052
|
+
}
|
|
48053
|
+
return Wallet.mlKemParameterSetFromPubkey(snapshot.pubkey) ?? 768;
|
|
48054
|
+
}
|
|
47920
48055
|
/**
|
|
47921
48056
|
* Restore AuthToken from snapshot
|
|
47922
48057
|
*/
|
|
@@ -47924,8 +48059,9 @@ ${operationTypes.join("\n")}
|
|
|
47924
48059
|
const wallet = new Wallet({
|
|
47925
48060
|
secret,
|
|
47926
48061
|
token: "AUTH",
|
|
47927
|
-
position: snapshot.wallet
|
|
47928
|
-
characters: snapshot.wallet
|
|
48062
|
+
position: snapshot.wallet?.position ?? null,
|
|
48063
|
+
characters: snapshot.wallet?.characters ?? null,
|
|
48064
|
+
mlKemParameterSet: _AuthToken.resolveMlKemParameterSet(snapshot)
|
|
47929
48065
|
});
|
|
47930
48066
|
return _AuthToken.create({
|
|
47931
48067
|
token: snapshot.token,
|
|
@@ -47993,7 +48129,9 @@ ${operationTypes.join("\n")}
|
|
|
47993
48129
|
};
|
|
47994
48130
|
}
|
|
47995
48131
|
/**
|
|
47996
|
-
* Create snapshot for persistence
|
|
48132
|
+
* Create snapshot for persistence. The wallet's ML-KEM parameter set is recorded beside its
|
|
48133
|
+
* position and characters so a stepped-back ML-KEM-768 session restores as 768 rather than
|
|
48134
|
+
* silently taking the constructor default.
|
|
47997
48135
|
*/
|
|
47998
48136
|
toSnapshot() {
|
|
47999
48137
|
return {
|
|
@@ -48004,7 +48142,8 @@ ${operationTypes.join("\n")}
|
|
|
48004
48142
|
...this.$__wallet ? {
|
|
48005
48143
|
wallet: {
|
|
48006
48144
|
position: this.$__wallet.position,
|
|
48007
|
-
characters: this.$__wallet.characters
|
|
48145
|
+
characters: this.$__wallet.characters,
|
|
48146
|
+
mlKemParameterSet: this.$__wallet.mlKemParameterSet
|
|
48008
48147
|
}
|
|
48009
48148
|
} : {}
|
|
48010
48149
|
};
|
|
@@ -48304,7 +48443,8 @@ ${operationTypes.join("\n")}
|
|
|
48304
48443
|
// isn't rejected.
|
|
48305
48444
|
defaultRequestPolicy: external_exports.enum(["cache-first", "cache-only", "network-only", "cache-and-network"]).nullable().optional(),
|
|
48306
48445
|
// Pluggable hardware envelope encryption secret storage provider
|
|
48307
|
-
secretStorage: external_exports.unknown().optional()
|
|
48446
|
+
secretStorage: external_exports.unknown().optional(),
|
|
48447
|
+
mlKemParameterSet: external_exports.union([external_exports.literal(1024), external_exports.literal(768)]).optional()
|
|
48308
48448
|
}).strict();
|
|
48309
48449
|
var EnvironmentConfigSchema = external_exports.object({
|
|
48310
48450
|
NODE_ENV: external_exports.enum(["development", "production", "test"]).optional(),
|
|
@@ -52028,6 +52168,7 @@ ${operationTypes.join("\n")}
|
|
|
52028
52168
|
$__authTokenObjects = {};
|
|
52029
52169
|
$__authToken = null;
|
|
52030
52170
|
$__authInProcess = false;
|
|
52171
|
+
$__mlKemParameterSet = 1024;
|
|
52031
52172
|
$__remainderWallet = null;
|
|
52032
52173
|
lastMoleculeQuery = null;
|
|
52033
52174
|
abortControllers = /* @__PURE__ */ new Map();
|
|
@@ -52072,7 +52213,8 @@ ${operationTypes.join("\n")}
|
|
|
52072
52213
|
client,
|
|
52073
52214
|
serverSdkVersion,
|
|
52074
52215
|
logging,
|
|
52075
|
-
defaultRequestPolicy
|
|
52216
|
+
defaultRequestPolicy,
|
|
52217
|
+
mlKemParameterSet: config2.mlKemParameterSet ?? 1024
|
|
52076
52218
|
});
|
|
52077
52219
|
if (config2.secretStorage) {
|
|
52078
52220
|
this.$__secretStorage = config2.secretStorage;
|
|
@@ -52088,10 +52230,12 @@ ${operationTypes.join("\n")}
|
|
|
52088
52230
|
client = null,
|
|
52089
52231
|
serverSdkVersion = 3,
|
|
52090
52232
|
logging = false,
|
|
52091
|
-
defaultRequestPolicy = null
|
|
52233
|
+
defaultRequestPolicy = null,
|
|
52234
|
+
mlKemParameterSet = 1024
|
|
52092
52235
|
}) {
|
|
52093
52236
|
this.reset();
|
|
52094
52237
|
this.$__logging = logging;
|
|
52238
|
+
this.setMlKemParameterSet(mlKemParameterSet);
|
|
52095
52239
|
this.$__authTokenObjects = {};
|
|
52096
52240
|
this.setUri(uri);
|
|
52097
52241
|
if (cellSlug) {
|
|
@@ -52112,6 +52256,17 @@ ${operationTypes.join("\n")}
|
|
|
52112
52256
|
this.$__serverSdkVersion = serverSdkVersion;
|
|
52113
52257
|
this.$__defaultRequestPolicy = defaultRequestPolicy;
|
|
52114
52258
|
}
|
|
52259
|
+
getMlKemParameterSet() {
|
|
52260
|
+
return this.$__mlKemParameterSet || 1024;
|
|
52261
|
+
}
|
|
52262
|
+
setMlKemParameterSet(parameterSet) {
|
|
52263
|
+
const paramNum = Number(parameterSet);
|
|
52264
|
+
if (![1024, 768].includes(paramNum)) {
|
|
52265
|
+
throw new Error(`KnishIO: unsupported ML-KEM parameter set ${parameterSet}; expected 1024 or 768.`);
|
|
52266
|
+
}
|
|
52267
|
+
this.$__mlKemParameterSet = paramNum;
|
|
52268
|
+
return this;
|
|
52269
|
+
}
|
|
52115
52270
|
/**
|
|
52116
52271
|
* Get random uri from specified this.$__uris
|
|
52117
52272
|
*/
|
|
@@ -52348,7 +52503,8 @@ ${operationTypes.join("\n")}
|
|
|
52348
52503
|
bundle,
|
|
52349
52504
|
token: "USER",
|
|
52350
52505
|
batchId: sourceWallet.batchId,
|
|
52351
|
-
characters: sourceWallet.characters
|
|
52506
|
+
characters: sourceWallet.characters,
|
|
52507
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52352
52508
|
}));
|
|
52353
52509
|
return new Molecule({
|
|
52354
52510
|
secret,
|
|
@@ -52357,7 +52513,8 @@ ${operationTypes.join("\n")}
|
|
|
52357
52513
|
remainderWallet: this.getRemainderWallet(),
|
|
52358
52514
|
cellSlug: this.getCellSlug(),
|
|
52359
52515
|
version: this.getServerSdkVersion(),
|
|
52360
|
-
continuIdPosition
|
|
52516
|
+
continuIdPosition,
|
|
52517
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52361
52518
|
});
|
|
52362
52519
|
}
|
|
52363
52520
|
/**
|
|
@@ -52469,7 +52626,8 @@ ${operationTypes.join("\n")}
|
|
|
52469
52626
|
}))?.payload();
|
|
52470
52627
|
if (!sourceWallet) {
|
|
52471
52628
|
sourceWallet = new Wallet({
|
|
52472
|
-
secret: this.getSecret()
|
|
52629
|
+
secret: this.getSecret(),
|
|
52630
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52473
52631
|
});
|
|
52474
52632
|
} else {
|
|
52475
52633
|
sourceWallet.key = Wallet.generateKey({
|
|
@@ -52512,7 +52670,8 @@ ${operationTypes.join("\n")}
|
|
|
52512
52670
|
}
|
|
52513
52671
|
const recipientWallet = Wallet.create({
|
|
52514
52672
|
bundle: bundleHash,
|
|
52515
|
-
token
|
|
52673
|
+
token,
|
|
52674
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52516
52675
|
});
|
|
52517
52676
|
if (batchId !== null) {
|
|
52518
52677
|
recipientWallet.batchId = batchId;
|
|
@@ -52579,7 +52738,8 @@ ${operationTypes.join("\n")}
|
|
|
52579
52738
|
const recipientWallets = recipients.map((recipient) => {
|
|
52580
52739
|
const recipientWallet = Wallet.create({
|
|
52581
52740
|
bundle: recipient.bundleHash,
|
|
52582
|
-
token
|
|
52741
|
+
token,
|
|
52742
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52583
52743
|
});
|
|
52584
52744
|
if (recipient.batchId !== null && recipient.batchId !== void 0) {
|
|
52585
52745
|
recipientWallet.batchId = recipient.batchId;
|
|
@@ -53203,7 +53363,8 @@ ${operationTypes.join("\n")}
|
|
|
53203
53363
|
secret: this.getSecret(),
|
|
53204
53364
|
bundle: this.getBundle(),
|
|
53205
53365
|
token,
|
|
53206
|
-
batchId
|
|
53366
|
+
batchId,
|
|
53367
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
53207
53368
|
});
|
|
53208
53369
|
await mutation.fillMolecule({
|
|
53209
53370
|
recipientWallet,
|
|
@@ -53271,7 +53432,8 @@ ${operationTypes.join("\n")}
|
|
|
53271
53432
|
const recipientWallet = new Wallet({
|
|
53272
53433
|
secret: this.getSecret(),
|
|
53273
53434
|
bundle: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
53274
|
-
token
|
|
53435
|
+
token,
|
|
53436
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
53275
53437
|
});
|
|
53276
53438
|
await mutation.fillMolecule({
|
|
53277
53439
|
recipientWallet,
|
|
@@ -53348,7 +53510,8 @@ ${operationTypes.join("\n")}
|
|
|
53348
53510
|
const newWallet = new Wallet({
|
|
53349
53511
|
secret: this.getSecret(),
|
|
53350
53512
|
bundle: this.getBundle(),
|
|
53351
|
-
token
|
|
53513
|
+
token,
|
|
53514
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
53352
53515
|
});
|
|
53353
53516
|
await mutation.fillMolecule(newWallet);
|
|
53354
53517
|
const response = await this.executeQuery(mutation);
|
|
@@ -53676,7 +53839,8 @@ ${operationTypes.join("\n")}
|
|
|
53676
53839
|
this.setSecret(secret);
|
|
53677
53840
|
const wallet = new Wallet({
|
|
53678
53841
|
secret,
|
|
53679
|
-
token: "AUTH"
|
|
53842
|
+
token: "AUTH",
|
|
53843
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
53680
53844
|
});
|
|
53681
53845
|
const molecule = await this.createMolecule({
|
|
53682
53846
|
secret,
|
|
@@ -54076,7 +54240,7 @@ ${operationTypes.join("\n")}
|
|
|
54076
54240
|
}
|
|
54077
54241
|
|
|
54078
54242
|
// src/index.ts
|
|
54079
|
-
var SDK_VERSION = "0.
|
|
54243
|
+
var SDK_VERSION = "1.0.0";
|
|
54080
54244
|
var SDK_NAME = "KnishIO-Client-TS";
|
|
54081
54245
|
var COMPATIBLE_SERVER_VERSIONS = [4, 5];
|
|
54082
54246
|
var SDK_INFO = {
|
|
@@ -54085,7 +54249,7 @@ ${operationTypes.join("\n")}
|
|
|
54085
54249
|
description: "TypeScript SDK for Knish.IO post-blockchain distributed ledger",
|
|
54086
54250
|
compatibleServerVersions: COMPATIBLE_SERVER_VERSIONS,
|
|
54087
54251
|
features: [
|
|
54088
|
-
"Post-quantum cryptography (XMSS, ML-
|
|
54252
|
+
"Post-quantum cryptography (XMSS, ML-KEM-1024)",
|
|
54089
54253
|
"Cross-platform compatibility",
|
|
54090
54254
|
"Type-safe APIs",
|
|
54091
54255
|
"DAG-based transaction processing",
|