@wishknish/knishio-client-ts 0.9.7 → 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 +237 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -36
- package/dist/index.d.ts +42 -36
- package/dist/index.iife.js +238 -52
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +238 -53
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/AuthToken.ts +47 -25
- package/src/KnishIOClient.ts +62 -17
- 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/mutation/MutationProposeMolecule.ts +7 -4
- 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(),
|
|
@@ -50902,6 +51042,13 @@ ${operationTypes.join("\n")}
|
|
|
50902
51042
|
molecule() {
|
|
50903
51043
|
return this.$__molecule.toJSON ? this.$__molecule.toJSON() : this.$__molecule;
|
|
50904
51044
|
}
|
|
51045
|
+
/**
|
|
51046
|
+
* Fills the molecule with specific mutation data.
|
|
51047
|
+
* Subclasses override to build domain-specific atoms.
|
|
51048
|
+
* Default implementation is a no-op for pre-assembled molecules.
|
|
51049
|
+
*/
|
|
51050
|
+
fillMolecule(_params) {
|
|
51051
|
+
}
|
|
50905
51052
|
};
|
|
50906
51053
|
|
|
50907
51054
|
// src/response/ResponseCreateToken.ts
|
|
@@ -52021,6 +52168,7 @@ ${operationTypes.join("\n")}
|
|
|
52021
52168
|
$__authTokenObjects = {};
|
|
52022
52169
|
$__authToken = null;
|
|
52023
52170
|
$__authInProcess = false;
|
|
52171
|
+
$__mlKemParameterSet = 1024;
|
|
52024
52172
|
$__remainderWallet = null;
|
|
52025
52173
|
lastMoleculeQuery = null;
|
|
52026
52174
|
abortControllers = /* @__PURE__ */ new Map();
|
|
@@ -52065,7 +52213,8 @@ ${operationTypes.join("\n")}
|
|
|
52065
52213
|
client,
|
|
52066
52214
|
serverSdkVersion,
|
|
52067
52215
|
logging,
|
|
52068
|
-
defaultRequestPolicy
|
|
52216
|
+
defaultRequestPolicy,
|
|
52217
|
+
mlKemParameterSet: config2.mlKemParameterSet ?? 1024
|
|
52069
52218
|
});
|
|
52070
52219
|
if (config2.secretStorage) {
|
|
52071
52220
|
this.$__secretStorage = config2.secretStorage;
|
|
@@ -52081,10 +52230,12 @@ ${operationTypes.join("\n")}
|
|
|
52081
52230
|
client = null,
|
|
52082
52231
|
serverSdkVersion = 3,
|
|
52083
52232
|
logging = false,
|
|
52084
|
-
defaultRequestPolicy = null
|
|
52233
|
+
defaultRequestPolicy = null,
|
|
52234
|
+
mlKemParameterSet = 1024
|
|
52085
52235
|
}) {
|
|
52086
52236
|
this.reset();
|
|
52087
52237
|
this.$__logging = logging;
|
|
52238
|
+
this.setMlKemParameterSet(mlKemParameterSet);
|
|
52088
52239
|
this.$__authTokenObjects = {};
|
|
52089
52240
|
this.setUri(uri);
|
|
52090
52241
|
if (cellSlug) {
|
|
@@ -52105,6 +52256,17 @@ ${operationTypes.join("\n")}
|
|
|
52105
52256
|
this.$__serverSdkVersion = serverSdkVersion;
|
|
52106
52257
|
this.$__defaultRequestPolicy = defaultRequestPolicy;
|
|
52107
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
|
+
}
|
|
52108
52270
|
/**
|
|
52109
52271
|
* Get random uri from specified this.$__uris
|
|
52110
52272
|
*/
|
|
@@ -52341,7 +52503,8 @@ ${operationTypes.join("\n")}
|
|
|
52341
52503
|
bundle,
|
|
52342
52504
|
token: "USER",
|
|
52343
52505
|
batchId: sourceWallet.batchId,
|
|
52344
|
-
characters: sourceWallet.characters
|
|
52506
|
+
characters: sourceWallet.characters,
|
|
52507
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52345
52508
|
}));
|
|
52346
52509
|
return new Molecule({
|
|
52347
52510
|
secret,
|
|
@@ -52350,7 +52513,8 @@ ${operationTypes.join("\n")}
|
|
|
52350
52513
|
remainderWallet: this.getRemainderWallet(),
|
|
52351
52514
|
cellSlug: this.getCellSlug(),
|
|
52352
52515
|
version: this.getServerSdkVersion(),
|
|
52353
|
-
continuIdPosition
|
|
52516
|
+
continuIdPosition,
|
|
52517
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52354
52518
|
});
|
|
52355
52519
|
}
|
|
52356
52520
|
/**
|
|
@@ -52462,7 +52626,8 @@ ${operationTypes.join("\n")}
|
|
|
52462
52626
|
}))?.payload();
|
|
52463
52627
|
if (!sourceWallet) {
|
|
52464
52628
|
sourceWallet = new Wallet({
|
|
52465
|
-
secret: this.getSecret()
|
|
52629
|
+
secret: this.getSecret(),
|
|
52630
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52466
52631
|
});
|
|
52467
52632
|
} else {
|
|
52468
52633
|
sourceWallet.key = Wallet.generateKey({
|
|
@@ -52505,7 +52670,8 @@ ${operationTypes.join("\n")}
|
|
|
52505
52670
|
}
|
|
52506
52671
|
const recipientWallet = Wallet.create({
|
|
52507
52672
|
bundle: bundleHash,
|
|
52508
|
-
token
|
|
52673
|
+
token,
|
|
52674
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52509
52675
|
});
|
|
52510
52676
|
if (batchId !== null) {
|
|
52511
52677
|
recipientWallet.batchId = batchId;
|
|
@@ -52572,7 +52738,8 @@ ${operationTypes.join("\n")}
|
|
|
52572
52738
|
const recipientWallets = recipients.map((recipient) => {
|
|
52573
52739
|
const recipientWallet = Wallet.create({
|
|
52574
52740
|
bundle: recipient.bundleHash,
|
|
52575
|
-
token
|
|
52741
|
+
token,
|
|
52742
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
52576
52743
|
});
|
|
52577
52744
|
if (recipient.batchId !== null && recipient.batchId !== void 0) {
|
|
52578
52745
|
recipientWallet.batchId = recipient.batchId;
|
|
@@ -53196,7 +53363,8 @@ ${operationTypes.join("\n")}
|
|
|
53196
53363
|
secret: this.getSecret(),
|
|
53197
53364
|
bundle: this.getBundle(),
|
|
53198
53365
|
token,
|
|
53199
|
-
batchId
|
|
53366
|
+
batchId,
|
|
53367
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
53200
53368
|
});
|
|
53201
53369
|
await mutation.fillMolecule({
|
|
53202
53370
|
recipientWallet,
|
|
@@ -53264,7 +53432,8 @@ ${operationTypes.join("\n")}
|
|
|
53264
53432
|
const recipientWallet = new Wallet({
|
|
53265
53433
|
secret: this.getSecret(),
|
|
53266
53434
|
bundle: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
53267
|
-
token
|
|
53435
|
+
token,
|
|
53436
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
53268
53437
|
});
|
|
53269
53438
|
await mutation.fillMolecule({
|
|
53270
53439
|
recipientWallet,
|
|
@@ -53341,7 +53510,8 @@ ${operationTypes.join("\n")}
|
|
|
53341
53510
|
const newWallet = new Wallet({
|
|
53342
53511
|
secret: this.getSecret(),
|
|
53343
53512
|
bundle: this.getBundle(),
|
|
53344
|
-
token
|
|
53513
|
+
token,
|
|
53514
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
53345
53515
|
});
|
|
53346
53516
|
await mutation.fillMolecule(newWallet);
|
|
53347
53517
|
const response = await this.executeQuery(mutation);
|
|
@@ -53472,15 +53642,30 @@ ${operationTypes.join("\n")}
|
|
|
53472
53642
|
async createPolicy({
|
|
53473
53643
|
metaType,
|
|
53474
53644
|
metaId,
|
|
53475
|
-
policy =
|
|
53645
|
+
policy = {}
|
|
53476
53646
|
}) {
|
|
53477
53647
|
this.log("info", `KnishIOClient::createPolicy() - Creating policy for ${metaType}:${metaId}...`);
|
|
53478
|
-
|
|
53648
|
+
const molecule = await this.createMolecule({});
|
|
53649
|
+
molecule.addPolicyAtom({
|
|
53479
53650
|
metaType,
|
|
53480
53651
|
metaId,
|
|
53481
|
-
meta:
|
|
53482
|
-
policy
|
|
53652
|
+
meta: {},
|
|
53653
|
+
policy: policy || {}
|
|
53483
53654
|
});
|
|
53655
|
+
molecule.addContinuIdAtom();
|
|
53656
|
+
molecule.sign({
|
|
53657
|
+
bundle: this.getBundle()
|
|
53658
|
+
});
|
|
53659
|
+
molecule.check();
|
|
53660
|
+
const query = await this.createMoleculeMutation({
|
|
53661
|
+
mutationClass: MutationProposeMolecule,
|
|
53662
|
+
molecule
|
|
53663
|
+
});
|
|
53664
|
+
const response = await this.executeQuery(query);
|
|
53665
|
+
if (!response) {
|
|
53666
|
+
throw new CodeException("Policy creation failed");
|
|
53667
|
+
}
|
|
53668
|
+
return response;
|
|
53484
53669
|
}
|
|
53485
53670
|
/**
|
|
53486
53671
|
* Create an identifier
|
|
@@ -53654,7 +53839,8 @@ ${operationTypes.join("\n")}
|
|
|
53654
53839
|
this.setSecret(secret);
|
|
53655
53840
|
const wallet = new Wallet({
|
|
53656
53841
|
secret,
|
|
53657
|
-
token: "AUTH"
|
|
53842
|
+
token: "AUTH",
|
|
53843
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
53658
53844
|
});
|
|
53659
53845
|
const molecule = await this.createMolecule({
|
|
53660
53846
|
secret,
|
|
@@ -54054,7 +54240,7 @@ ${operationTypes.join("\n")}
|
|
|
54054
54240
|
}
|
|
54055
54241
|
|
|
54056
54242
|
// src/index.ts
|
|
54057
|
-
var SDK_VERSION = "0.
|
|
54243
|
+
var SDK_VERSION = "1.0.0";
|
|
54058
54244
|
var SDK_NAME = "KnishIO-Client-TS";
|
|
54059
54245
|
var COMPATIBLE_SERVER_VERSIONS = [4, 5];
|
|
54060
54246
|
var SDK_INFO = {
|
|
@@ -54063,7 +54249,7 @@ ${operationTypes.join("\n")}
|
|
|
54063
54249
|
description: "TypeScript SDK for Knish.IO post-blockchain distributed ledger",
|
|
54064
54250
|
compatibleServerVersions: COMPATIBLE_SERVER_VERSIONS,
|
|
54065
54251
|
features: [
|
|
54066
|
-
"Post-quantum cryptography (XMSS, ML-
|
|
54252
|
+
"Post-quantum cryptography (XMSS, ML-KEM-1024)",
|
|
54067
54253
|
"Cross-platform compatibility",
|
|
54068
54254
|
"Type-safe APIs",
|
|
54069
54255
|
"DAG-based transaction processing",
|