@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.cjs
CHANGED
|
@@ -3661,6 +3661,11 @@ var TokenUnit = class _TokenUnit {
|
|
|
3661
3661
|
};
|
|
3662
3662
|
}
|
|
3663
3663
|
};
|
|
3664
|
+
var ML_KEM_PARAMS = {
|
|
3665
|
+
1024: { kem: mlKem_js.ml_kem1024, pkBytes: 1568, skBytes: 3168, ctBytes: 1568 },
|
|
3666
|
+
768: { kem: mlKem_js.ml_kem768, pkBytes: 1184, skBytes: 2400, ctBytes: 1088 }
|
|
3667
|
+
};
|
|
3668
|
+
var DEFAULT_ML_KEM_PARAMETER_SET = 1024;
|
|
3664
3669
|
var Wallet = class _Wallet {
|
|
3665
3670
|
token;
|
|
3666
3671
|
balance;
|
|
@@ -3675,6 +3680,7 @@ var Wallet = class _Wallet {
|
|
|
3675
3680
|
tokenUnits;
|
|
3676
3681
|
tradeRates;
|
|
3677
3682
|
molecules;
|
|
3683
|
+
mlKemParameterSet;
|
|
3678
3684
|
// Token metadata (populated from query responses)
|
|
3679
3685
|
tokenName;
|
|
3680
3686
|
tokenAmount;
|
|
@@ -3688,8 +3694,14 @@ var Wallet = class _Wallet {
|
|
|
3688
3694
|
address = null,
|
|
3689
3695
|
position = null,
|
|
3690
3696
|
batchId = null,
|
|
3691
|
-
characters = null
|
|
3697
|
+
characters = null,
|
|
3698
|
+
mlKemParameterSet = DEFAULT_ML_KEM_PARAMETER_SET
|
|
3692
3699
|
} = {}) {
|
|
3700
|
+
const paramSetNum = Number(mlKemParameterSet);
|
|
3701
|
+
if (!ML_KEM_PARAMS[paramSetNum]) {
|
|
3702
|
+
throw new Error(`KnishIO: unsupported ML-KEM parameter set ${mlKemParameterSet}; expected 1024 or 768.`);
|
|
3703
|
+
}
|
|
3704
|
+
this.mlKemParameterSet = paramSetNum;
|
|
3693
3705
|
this.token = token;
|
|
3694
3706
|
this.balance = "0";
|
|
3695
3707
|
this.molecules = {};
|
|
@@ -3725,7 +3737,8 @@ var Wallet = class _Wallet {
|
|
|
3725
3737
|
bundle = null,
|
|
3726
3738
|
token = "USER",
|
|
3727
3739
|
batchId = null,
|
|
3728
|
-
characters = null
|
|
3740
|
+
characters = null,
|
|
3741
|
+
mlKemParameterSet = DEFAULT_ML_KEM_PARAMETER_SET
|
|
3729
3742
|
}) {
|
|
3730
3743
|
let position = null;
|
|
3731
3744
|
if (!secret && !bundle) {
|
|
@@ -3741,7 +3754,8 @@ var Wallet = class _Wallet {
|
|
|
3741
3754
|
token,
|
|
3742
3755
|
position,
|
|
3743
3756
|
batchId,
|
|
3744
|
-
characters
|
|
3757
|
+
characters,
|
|
3758
|
+
mlKemParameterSet
|
|
3745
3759
|
});
|
|
3746
3760
|
}
|
|
3747
3761
|
/**
|
|
@@ -3900,20 +3914,80 @@ var Wallet = class _Wallet {
|
|
|
3900
3914
|
return (typeof this.position === "undefined" || this.position === null) && (typeof this.address === "undefined" || this.address === null);
|
|
3901
3915
|
}
|
|
3902
3916
|
// =============================================================================
|
|
3903
|
-
// POST-QUANTUM CRYPTOGRAPHY - ML-
|
|
3917
|
+
// POST-QUANTUM CRYPTOGRAPHY - ML-KEM INTEGRATION
|
|
3904
3918
|
// =============================================================================
|
|
3905
3919
|
/**
|
|
3906
|
-
*
|
|
3920
|
+
* Derive an ML-KEM keypair for an arbitrary parameter set from the wallet's key seed,
|
|
3921
|
+
* without mutating the wallet. The 64-byte `d‖z` seed takes no parameter-set input — only
|
|
3922
|
+
* the final `keygen` call differs — so one KnishIO wallet owns both an ML-KEM-768 and an
|
|
3923
|
+
* ML-KEM-1024 identity and either can be reconstructed on demand.
|
|
3924
|
+
*
|
|
3925
|
+
* Returns `null` when the wallet holds no key — a secret-less wallet, which is what a molecule
|
|
3926
|
+
* deserializer builds for validation context. `generateSecret(null, …)` does NOT throw, so
|
|
3927
|
+
* without this the wallet would derive a plausible-looking identity from a bogus seed and fail
|
|
3928
|
+
* three layers down at AES-GCM instead of at the missing key. The guard lives here rather than
|
|
3929
|
+
* at each call site so a new caller cannot miss it.
|
|
3930
|
+
*
|
|
3931
|
+
* @param parameterSet - 1024 or 768
|
|
3907
3932
|
*/
|
|
3908
|
-
|
|
3933
|
+
deriveMlKemKeypair(parameterSet) {
|
|
3934
|
+
const params = ML_KEM_PARAMS[parameterSet];
|
|
3935
|
+
if (!params) {
|
|
3936
|
+
throw new Error(`KnishIO: unsupported ML-KEM parameter set ${parameterSet}; expected 1024 or 768.`);
|
|
3937
|
+
}
|
|
3938
|
+
if (!this.key) {
|
|
3939
|
+
return null;
|
|
3940
|
+
}
|
|
3909
3941
|
const seedHex = generateSecret(this.key, 128);
|
|
3910
3942
|
const seed = new Uint8Array(64);
|
|
3911
3943
|
for (let i = 0; i < 64; i++) {
|
|
3912
3944
|
seed[i] = parseInt(seedHex.substr(i * 2, 2), 16);
|
|
3913
3945
|
}
|
|
3914
|
-
const { publicKey, secretKey } =
|
|
3915
|
-
|
|
3916
|
-
|
|
3946
|
+
const { publicKey, secretKey } = params.kem.keygen(seed);
|
|
3947
|
+
return {
|
|
3948
|
+
pubkey: this.serializeKey(publicKey),
|
|
3949
|
+
privkey: secretKey,
|
|
3950
|
+
params
|
|
3951
|
+
};
|
|
3952
|
+
}
|
|
3953
|
+
/**
|
|
3954
|
+
* ML-KEM parameter set implied by a serialized public key's raw byte length. FIPS 203's key
|
|
3955
|
+
* lengths are disjoint (1568 bytes → ML-KEM-1024, 1184 bytes → ML-KEM-768), so a stored peer
|
|
3956
|
+
* key recovers the parameter set of the session it belongs to without a wire-format change.
|
|
3957
|
+
* Used by AuthToken.restore to resolve a snapshot that predates the field.
|
|
3958
|
+
*
|
|
3959
|
+
* @param pubkey - Base64-serialized ML-KEM public key
|
|
3960
|
+
* @return 1024, 768, or null when the length matches neither
|
|
3961
|
+
*/
|
|
3962
|
+
static mlKemParameterSetFromPubkey(pubkey) {
|
|
3963
|
+
if (!pubkey) {
|
|
3964
|
+
return null;
|
|
3965
|
+
}
|
|
3966
|
+
let byteLength;
|
|
3967
|
+
try {
|
|
3968
|
+
byteLength = typeof Buffer !== "undefined" ? Buffer.from(pubkey, "base64").length : atob(pubkey).length;
|
|
3969
|
+
} catch {
|
|
3970
|
+
return null;
|
|
3971
|
+
}
|
|
3972
|
+
if (byteLength === ML_KEM_PARAMS[1024].pkBytes) {
|
|
3973
|
+
return 1024;
|
|
3974
|
+
}
|
|
3975
|
+
if (byteLength === ML_KEM_PARAMS[768].pkBytes) {
|
|
3976
|
+
return 768;
|
|
3977
|
+
}
|
|
3978
|
+
return null;
|
|
3979
|
+
}
|
|
3980
|
+
/**
|
|
3981
|
+
* Initializes the ML-KEM key pair (matches JavaScript SDK exactly). Only ever reached from the
|
|
3982
|
+
* constructor's `secret` branch, so the derivation cannot come back empty here.
|
|
3983
|
+
*/
|
|
3984
|
+
initializeMLKEM() {
|
|
3985
|
+
const derived = this.deriveMlKemKeypair(this.mlKemParameterSet);
|
|
3986
|
+
if (!derived) {
|
|
3987
|
+
return;
|
|
3988
|
+
}
|
|
3989
|
+
this.pubkey = derived.pubkey;
|
|
3990
|
+
this.privkey = derived.privkey;
|
|
3917
3991
|
}
|
|
3918
3992
|
// =============================================================================
|
|
3919
3993
|
// HIGH-LEVEL MESSAGE ENCRYPTION (JavaScript SDK Compatibility)
|
|
@@ -3922,13 +3996,13 @@ var Wallet = class _Wallet {
|
|
|
3922
3996
|
const messageString = JSON.stringify(message);
|
|
3923
3997
|
const messageUint8 = new TextEncoder().encode(messageString);
|
|
3924
3998
|
const deserializedPubkey = this.deserializeKey(recipientPubkey);
|
|
3925
|
-
const
|
|
3926
|
-
if (deserializedPubkey.length !==
|
|
3999
|
+
const params = ML_KEM_PARAMS[this.mlKemParameterSet];
|
|
4000
|
+
if (deserializedPubkey.length !== params.pkBytes) {
|
|
3927
4001
|
throw new Error(
|
|
3928
|
-
`KnishIO: cannot ML-KEM-encrypt \u2014 recipient public key is ${deserializedPubkey.length} bytes, expected ${
|
|
4002
|
+
`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.`
|
|
3929
4003
|
);
|
|
3930
4004
|
}
|
|
3931
|
-
const { cipherText, sharedSecret } =
|
|
4005
|
+
const { cipherText, sharedSecret } = params.kem.encapsulate(deserializedPubkey);
|
|
3932
4006
|
const encryptedMessage = await this.encryptWithSharedSecret(messageUint8, sharedSecret);
|
|
3933
4007
|
return {
|
|
3934
4008
|
cipherText: this.serializeKey(cipherText),
|
|
@@ -3940,15 +4014,37 @@ var Wallet = class _Wallet {
|
|
|
3940
4014
|
return decryptedString === null ? null : JSON.parse(decryptedString);
|
|
3941
4015
|
}
|
|
3942
4016
|
/**
|
|
3943
|
-
* ML-
|
|
4017
|
+
* ML-KEM decapsulate + AES-256-GCM decrypt → the RAW decrypted UTF-8 string (no JSON.parse).
|
|
3944
4018
|
* Shared by {@link decryptMessage} (which JSON.parses the result) and the PQ CipherHash transport
|
|
3945
|
-
* ({@link
|
|
4019
|
+
* ({@link decryptMyMessageML}, which needs the raw response JSON text). PQ-transport Phase E.
|
|
3946
4020
|
*/
|
|
3947
4021
|
async _mlkemDecryptToString(encryptedData) {
|
|
3948
4022
|
const { cipherText, encryptedMessage } = encryptedData;
|
|
4023
|
+
const configuredParams = ML_KEM_PARAMS[this.mlKemParameterSet];
|
|
4024
|
+
const otherSet = this.mlKemParameterSet === 1024 ? 768 : 1024;
|
|
4025
|
+
const deserializedCipherText = this.deserializeKey(cipherText);
|
|
4026
|
+
let params = configuredParams;
|
|
4027
|
+
let decapsPrivkey = this.privkey;
|
|
4028
|
+
if (deserializedCipherText.length !== configuredParams.ctBytes) {
|
|
4029
|
+
if (deserializedCipherText.length !== ML_KEM_PARAMS[otherSet].ctBytes) {
|
|
4030
|
+
console.error(
|
|
4031
|
+
`Wallet::decryptMessage() - Ciphertext length mismatch: got ${deserializedCipherText.length}, expected ${configuredParams.ctBytes}`
|
|
4032
|
+
);
|
|
4033
|
+
return null;
|
|
4034
|
+
}
|
|
4035
|
+
const derived = this.deriveMlKemKeypair(otherSet);
|
|
4036
|
+
if (!derived) {
|
|
4037
|
+
console.error(
|
|
4038
|
+
`Wallet::decryptMessage() - cannot derive the ML-KEM-${otherSet} identity: wallet has no key`
|
|
4039
|
+
);
|
|
4040
|
+
return null;
|
|
4041
|
+
}
|
|
4042
|
+
params = derived.params;
|
|
4043
|
+
decapsPrivkey = derived.privkey;
|
|
4044
|
+
}
|
|
3949
4045
|
let sharedSecret;
|
|
3950
4046
|
try {
|
|
3951
|
-
sharedSecret =
|
|
4047
|
+
sharedSecret = params.kem.decapsulate(deserializedCipherText, decapsPrivkey);
|
|
3952
4048
|
} catch (e) {
|
|
3953
4049
|
console.error("Wallet::decryptMessage() - Decapsulation failed", e);
|
|
3954
4050
|
console.info("Wallet::decryptMessage() - my public key", this.pubkey);
|
|
@@ -3998,11 +4094,11 @@ var Wallet = class _Wallet {
|
|
|
3998
4094
|
return this.serializeKey(bytes);
|
|
3999
4095
|
}
|
|
4000
4096
|
/**
|
|
4001
|
-
* Post-quantum (ML-
|
|
4097
|
+
* Post-quantum (ML-KEM) CipherHash request envelope: a stringified single-recipient map
|
|
4002
4098
|
* `{ "<hashShare(recipientPubkey)>": {cipherText, encryptedMessage} }` (object-valued, via
|
|
4003
4099
|
* {@link encryptMessage}). Matches the Rust validator's CipherHash handler. PQ-transport Phase E.
|
|
4004
4100
|
*/
|
|
4005
|
-
async
|
|
4101
|
+
async encryptStringML(message, recipientPubkey) {
|
|
4006
4102
|
const envelope = await this.encryptMessage(message, recipientPubkey);
|
|
4007
4103
|
return JSON.stringify({ [this.hashShare(recipientPubkey)]: envelope });
|
|
4008
4104
|
}
|
|
@@ -4010,9 +4106,21 @@ var Wallet = class _Wallet {
|
|
|
4010
4106
|
* Decrypt a CipherHash response map addressed to THIS wallet's ML-KEM pubkey
|
|
4011
4107
|
* (`hashShare(this.pubkey)`) → the RAW decrypted GraphQL response JSON text (NOT JSON.parsed;
|
|
4012
4108
|
* it replaces the HTTP response body for the normal parser). `null` if no entry / decrypt fails.
|
|
4109
|
+
*
|
|
4110
|
+
* A pre-bump peer addressed its envelope to `hashShare(our_768_pubkey)`, which a wallet
|
|
4111
|
+
* configured at ML-KEM-1024 would never find — so the other identity's share is tried too.
|
|
4112
|
+
* Without this, the permissive length dispatch in {@link _mlkemDecryptToString} is
|
|
4113
|
+
* unreachable on the transport path.
|
|
4013
4114
|
*/
|
|
4014
|
-
async
|
|
4015
|
-
|
|
4115
|
+
async decryptMyMessageML(map) {
|
|
4116
|
+
let envelope = map[this.hashShare(this.pubkey)];
|
|
4117
|
+
if (!envelope) {
|
|
4118
|
+
const otherSet = this.mlKemParameterSet === 1024 ? 768 : 1024;
|
|
4119
|
+
const other = this.deriveMlKemKeypair(otherSet);
|
|
4120
|
+
if (other) {
|
|
4121
|
+
envelope = map[this.hashShare(other.pubkey)];
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4016
4124
|
if (!envelope) {
|
|
4017
4125
|
return null;
|
|
4018
4126
|
}
|
|
@@ -4166,7 +4274,8 @@ zod.z.object({
|
|
|
4166
4274
|
serverSdkVersion: zod.z.number().int().min(1).optional(),
|
|
4167
4275
|
logging: zod.z.boolean().optional(),
|
|
4168
4276
|
defaultRequestPolicy: zod.z.enum(["cache-first", "cache-only", "network-only", "cache-and-network"]).nullable().optional(),
|
|
4169
|
-
secretStorage: zod.z.unknown().optional()
|
|
4277
|
+
secretStorage: zod.z.unknown().optional(),
|
|
4278
|
+
mlKemParameterSet: zod.z.union([zod.z.literal(1024), zod.z.literal(768)]).optional()
|
|
4170
4279
|
}).strict();
|
|
4171
4280
|
zod.z.object({
|
|
4172
4281
|
token: zod.z.string().min(1, "Auth token cannot be empty"),
|
|
@@ -5255,6 +5364,7 @@ var Molecule = class _Molecule {
|
|
|
5255
5364
|
continuIdPosition;
|
|
5256
5365
|
parentHashes;
|
|
5257
5366
|
local;
|
|
5367
|
+
mlKemParameterSet = 1024;
|
|
5258
5368
|
/**
|
|
5259
5369
|
* Create new Molecule instance
|
|
5260
5370
|
* Matches JavaScript SDK constructor signature
|
|
@@ -5266,7 +5376,8 @@ var Molecule = class _Molecule {
|
|
|
5266
5376
|
remainderWallet = null,
|
|
5267
5377
|
cellSlug = null,
|
|
5268
5378
|
version = null,
|
|
5269
|
-
continuIdPosition = null
|
|
5379
|
+
continuIdPosition = null,
|
|
5380
|
+
mlKemParameterSet = null
|
|
5270
5381
|
} = {}) {
|
|
5271
5382
|
this.status = null;
|
|
5272
5383
|
this.molecularHash = null;
|
|
@@ -5278,6 +5389,7 @@ var Molecule = class _Molecule {
|
|
|
5278
5389
|
this.continuIdPosition = continuIdPosition;
|
|
5279
5390
|
this.atoms = [];
|
|
5280
5391
|
this.parentHashes = [];
|
|
5392
|
+
this.mlKemParameterSet = mlKemParameterSet || sourceWallet?.mlKemParameterSet || 1024;
|
|
5281
5393
|
const versionRegistry = versions_default;
|
|
5282
5394
|
if (version !== null && Object.prototype.hasOwnProperty.call(versionRegistry, version)) {
|
|
5283
5395
|
this.version = String(version);
|
|
@@ -5288,7 +5400,8 @@ var Molecule = class _Molecule {
|
|
|
5288
5400
|
bundle,
|
|
5289
5401
|
token: sourceWallet.token,
|
|
5290
5402
|
batchId: sourceWallet.batchId,
|
|
5291
|
-
characters: sourceWallet.characters
|
|
5403
|
+
characters: sourceWallet.characters,
|
|
5404
|
+
mlKemParameterSet: this.mlKemParameterSet
|
|
5292
5405
|
});
|
|
5293
5406
|
} else {
|
|
5294
5407
|
this.remainderWallet = null;
|
|
@@ -5349,7 +5462,8 @@ var Molecule = class _Molecule {
|
|
|
5349
5462
|
if (!this.remainderWallet || this.remainderWallet.token !== "USER") {
|
|
5350
5463
|
this.remainderWallet = Wallet.create({
|
|
5351
5464
|
secret: this.secret,
|
|
5352
|
-
bundle: this.bundle
|
|
5465
|
+
bundle: this.bundle,
|
|
5466
|
+
mlKemParameterSet: this.mlKemParameterSet
|
|
5353
5467
|
});
|
|
5354
5468
|
}
|
|
5355
5469
|
const continuIdMeta = {};
|
|
@@ -5736,7 +5850,8 @@ var Molecule = class _Molecule {
|
|
|
5736
5850
|
}
|
|
5737
5851
|
const burnWallet = new Wallet({
|
|
5738
5852
|
bundle: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
5739
|
-
token: this.sourceWallet.token
|
|
5853
|
+
token: this.sourceWallet.token,
|
|
5854
|
+
mlKemParameterSet: this.mlKemParameterSet
|
|
5740
5855
|
});
|
|
5741
5856
|
this.addAtom(Atom.create({
|
|
5742
5857
|
isotope: "V",
|
|
@@ -6008,7 +6123,8 @@ var Molecule = class _Molecule {
|
|
|
6008
6123
|
position: data.sourceWallet.position,
|
|
6009
6124
|
bundle: data.sourceWallet.bundle,
|
|
6010
6125
|
batchId: data.sourceWallet.batchId,
|
|
6011
|
-
characters: data.sourceWallet.characters
|
|
6126
|
+
characters: data.sourceWallet.characters,
|
|
6127
|
+
mlKemParameterSet: molecule.mlKemParameterSet
|
|
6012
6128
|
});
|
|
6013
6129
|
molecule.sourceWallet.balance = String(data.sourceWallet.balance != null ? data.sourceWallet.balance : 0);
|
|
6014
6130
|
molecule.sourceWallet.address = data.sourceWallet.address;
|
|
@@ -6026,7 +6142,8 @@ var Molecule = class _Molecule {
|
|
|
6026
6142
|
position: data.remainderWallet.position,
|
|
6027
6143
|
bundle: data.remainderWallet.bundle,
|
|
6028
6144
|
batchId: data.remainderWallet.batchId,
|
|
6029
|
-
characters: data.remainderWallet.characters
|
|
6145
|
+
characters: data.remainderWallet.characters,
|
|
6146
|
+
mlKemParameterSet: molecule.mlKemParameterSet
|
|
6030
6147
|
});
|
|
6031
6148
|
molecule.remainderWallet.balance = String(data.remainderWallet.balance != null ? data.remainderWallet.balance : 0);
|
|
6032
6149
|
molecule.remainderWallet.address = data.remainderWallet.address;
|
|
@@ -6124,7 +6241,8 @@ var Molecule = class _Molecule {
|
|
|
6124
6241
|
secret: this.secret,
|
|
6125
6242
|
bundle: this.bundle,
|
|
6126
6243
|
token: this.sourceWallet.token,
|
|
6127
|
-
batchId: this.sourceWallet.batchId
|
|
6244
|
+
batchId: this.sourceWallet.batchId,
|
|
6245
|
+
mlKemParameterSet: this.mlKemParameterSet
|
|
6128
6246
|
});
|
|
6129
6247
|
if (tradeRates) {
|
|
6130
6248
|
bufferWallet.tradeRates = tradeRates;
|
|
@@ -6395,7 +6513,7 @@ var GraphQLClient = class {
|
|
|
6395
6513
|
let encryptedRequest = false;
|
|
6396
6514
|
let requestInit = init;
|
|
6397
6515
|
if (wallet && serverPubkey && init && typeof init.body === "string" && this.shouldEncrypt(init.body)) {
|
|
6398
|
-
const hashVar = await wallet.
|
|
6516
|
+
const hashVar = await wallet.encryptStringML(init.body, serverPubkey);
|
|
6399
6517
|
requestInit = { ...init, body: JSON.stringify({ query: CIPHER_HASH_QUERY, variables: { Hash: hashVar } }) };
|
|
6400
6518
|
encryptedRequest = true;
|
|
6401
6519
|
}
|
|
@@ -6415,7 +6533,7 @@ var GraphQLClient = class {
|
|
|
6415
6533
|
if (typeof hash !== "string") {
|
|
6416
6534
|
return new Response(text, init2);
|
|
6417
6535
|
}
|
|
6418
|
-
const decrypted = await wallet.
|
|
6536
|
+
const decrypted = await wallet.decryptMyMessageML(JSON.parse(hash));
|
|
6419
6537
|
return new Response(decrypted != null ? decrypted : text, init2);
|
|
6420
6538
|
}
|
|
6421
6539
|
setAuthData({
|
|
@@ -6584,6 +6702,22 @@ var AuthToken = class _AuthToken {
|
|
|
6584
6702
|
authToken.setWallet(wallet);
|
|
6585
6703
|
return authToken;
|
|
6586
6704
|
}
|
|
6705
|
+
/**
|
|
6706
|
+
* ML-KEM parameter set a restored session must use, resolved in three tiers:
|
|
6707
|
+
* an explicit snapshot field, then the stored validator key's length, then ML-KEM-768.
|
|
6708
|
+
*
|
|
6709
|
+
* The final tier is deliberately NOT the constructor default. A snapshot with neither an
|
|
6710
|
+
* explicit field nor a recognisable key can only have come from a pre-bump build, and every
|
|
6711
|
+
* pre-bump build was 768-only — defaulting to 1024 would make the restored wallet advertise
|
|
6712
|
+
* a public key the validator never recorded for that token.
|
|
6713
|
+
*/
|
|
6714
|
+
static resolveMlKemParameterSet(snapshot) {
|
|
6715
|
+
const explicit = snapshot.wallet?.mlKemParameterSet;
|
|
6716
|
+
if (explicit) {
|
|
6717
|
+
return Number(explicit) === 768 ? 768 : 1024;
|
|
6718
|
+
}
|
|
6719
|
+
return Wallet.mlKemParameterSetFromPubkey(snapshot.pubkey) ?? 768;
|
|
6720
|
+
}
|
|
6587
6721
|
/**
|
|
6588
6722
|
* Restore AuthToken from snapshot
|
|
6589
6723
|
*/
|
|
@@ -6591,8 +6725,9 @@ var AuthToken = class _AuthToken {
|
|
|
6591
6725
|
const wallet = new Wallet({
|
|
6592
6726
|
secret,
|
|
6593
6727
|
token: "AUTH",
|
|
6594
|
-
position: snapshot.wallet
|
|
6595
|
-
characters: snapshot.wallet
|
|
6728
|
+
position: snapshot.wallet?.position ?? null,
|
|
6729
|
+
characters: snapshot.wallet?.characters ?? null,
|
|
6730
|
+
mlKemParameterSet: _AuthToken.resolveMlKemParameterSet(snapshot)
|
|
6596
6731
|
});
|
|
6597
6732
|
return _AuthToken.create({
|
|
6598
6733
|
token: snapshot.token,
|
|
@@ -6660,7 +6795,9 @@ var AuthToken = class _AuthToken {
|
|
|
6660
6795
|
};
|
|
6661
6796
|
}
|
|
6662
6797
|
/**
|
|
6663
|
-
* Create snapshot for persistence
|
|
6798
|
+
* Create snapshot for persistence. The wallet's ML-KEM parameter set is recorded beside its
|
|
6799
|
+
* position and characters so a stepped-back ML-KEM-768 session restores as 768 rather than
|
|
6800
|
+
* silently taking the constructor default.
|
|
6664
6801
|
*/
|
|
6665
6802
|
toSnapshot() {
|
|
6666
6803
|
return {
|
|
@@ -6671,7 +6808,8 @@ var AuthToken = class _AuthToken {
|
|
|
6671
6808
|
...this.$__wallet ? {
|
|
6672
6809
|
wallet: {
|
|
6673
6810
|
position: this.$__wallet.position,
|
|
6674
|
-
characters: this.$__wallet.characters
|
|
6811
|
+
characters: this.$__wallet.characters,
|
|
6812
|
+
mlKemParameterSet: this.$__wallet.mlKemParameterSet
|
|
6675
6813
|
}
|
|
6676
6814
|
} : {}
|
|
6677
6815
|
};
|
|
@@ -6968,7 +7106,8 @@ var KnishIOClientConfigSchema2 = zod.z.object({
|
|
|
6968
7106
|
// isn't rejected.
|
|
6969
7107
|
defaultRequestPolicy: zod.z.enum(["cache-first", "cache-only", "network-only", "cache-and-network"]).nullable().optional(),
|
|
6970
7108
|
// Pluggable hardware envelope encryption secret storage provider
|
|
6971
|
-
secretStorage: zod.z.unknown().optional()
|
|
7109
|
+
secretStorage: zod.z.unknown().optional(),
|
|
7110
|
+
mlKemParameterSet: zod.z.union([zod.z.literal(1024), zod.z.literal(768)]).optional()
|
|
6972
7111
|
}).strict();
|
|
6973
7112
|
var EnvironmentConfigSchema = zod.z.object({
|
|
6974
7113
|
NODE_ENV: zod.z.enum(["development", "production", "test"]).optional(),
|
|
@@ -10654,6 +10793,7 @@ var KnishIOClient = class {
|
|
|
10654
10793
|
$__authTokenObjects = {};
|
|
10655
10794
|
$__authToken = null;
|
|
10656
10795
|
$__authInProcess = false;
|
|
10796
|
+
$__mlKemParameterSet = 1024;
|
|
10657
10797
|
$__remainderWallet = null;
|
|
10658
10798
|
lastMoleculeQuery = null;
|
|
10659
10799
|
abortControllers = /* @__PURE__ */ new Map();
|
|
@@ -10698,7 +10838,8 @@ var KnishIOClient = class {
|
|
|
10698
10838
|
client,
|
|
10699
10839
|
serverSdkVersion,
|
|
10700
10840
|
logging,
|
|
10701
|
-
defaultRequestPolicy
|
|
10841
|
+
defaultRequestPolicy,
|
|
10842
|
+
mlKemParameterSet: config.mlKemParameterSet ?? 1024
|
|
10702
10843
|
});
|
|
10703
10844
|
if (config.secretStorage) {
|
|
10704
10845
|
this.$__secretStorage = config.secretStorage;
|
|
@@ -10714,10 +10855,12 @@ var KnishIOClient = class {
|
|
|
10714
10855
|
client = null,
|
|
10715
10856
|
serverSdkVersion = 3,
|
|
10716
10857
|
logging = false,
|
|
10717
|
-
defaultRequestPolicy = null
|
|
10858
|
+
defaultRequestPolicy = null,
|
|
10859
|
+
mlKemParameterSet = 1024
|
|
10718
10860
|
}) {
|
|
10719
10861
|
this.reset();
|
|
10720
10862
|
this.$__logging = logging;
|
|
10863
|
+
this.setMlKemParameterSet(mlKemParameterSet);
|
|
10721
10864
|
this.$__authTokenObjects = {};
|
|
10722
10865
|
this.setUri(uri);
|
|
10723
10866
|
if (cellSlug) {
|
|
@@ -10738,6 +10881,17 @@ var KnishIOClient = class {
|
|
|
10738
10881
|
this.$__serverSdkVersion = serverSdkVersion;
|
|
10739
10882
|
this.$__defaultRequestPolicy = defaultRequestPolicy;
|
|
10740
10883
|
}
|
|
10884
|
+
getMlKemParameterSet() {
|
|
10885
|
+
return this.$__mlKemParameterSet || 1024;
|
|
10886
|
+
}
|
|
10887
|
+
setMlKemParameterSet(parameterSet) {
|
|
10888
|
+
const paramNum = Number(parameterSet);
|
|
10889
|
+
if (![1024, 768].includes(paramNum)) {
|
|
10890
|
+
throw new Error(`KnishIO: unsupported ML-KEM parameter set ${parameterSet}; expected 1024 or 768.`);
|
|
10891
|
+
}
|
|
10892
|
+
this.$__mlKemParameterSet = paramNum;
|
|
10893
|
+
return this;
|
|
10894
|
+
}
|
|
10741
10895
|
/**
|
|
10742
10896
|
* Get random uri from specified this.$__uris
|
|
10743
10897
|
*/
|
|
@@ -10974,7 +11128,8 @@ var KnishIOClient = class {
|
|
|
10974
11128
|
bundle,
|
|
10975
11129
|
token: "USER",
|
|
10976
11130
|
batchId: sourceWallet.batchId,
|
|
10977
|
-
characters: sourceWallet.characters
|
|
11131
|
+
characters: sourceWallet.characters,
|
|
11132
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
10978
11133
|
}));
|
|
10979
11134
|
return new Molecule({
|
|
10980
11135
|
secret,
|
|
@@ -10983,7 +11138,8 @@ var KnishIOClient = class {
|
|
|
10983
11138
|
remainderWallet: this.getRemainderWallet(),
|
|
10984
11139
|
cellSlug: this.getCellSlug(),
|
|
10985
11140
|
version: this.getServerSdkVersion(),
|
|
10986
|
-
continuIdPosition
|
|
11141
|
+
continuIdPosition,
|
|
11142
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
10987
11143
|
});
|
|
10988
11144
|
}
|
|
10989
11145
|
/**
|
|
@@ -11095,7 +11251,8 @@ var KnishIOClient = class {
|
|
|
11095
11251
|
}))?.payload();
|
|
11096
11252
|
if (!sourceWallet) {
|
|
11097
11253
|
sourceWallet = new Wallet({
|
|
11098
|
-
secret: this.getSecret()
|
|
11254
|
+
secret: this.getSecret(),
|
|
11255
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
11099
11256
|
});
|
|
11100
11257
|
} else {
|
|
11101
11258
|
sourceWallet.key = Wallet.generateKey({
|
|
@@ -11138,7 +11295,8 @@ var KnishIOClient = class {
|
|
|
11138
11295
|
}
|
|
11139
11296
|
const recipientWallet = Wallet.create({
|
|
11140
11297
|
bundle: bundleHash,
|
|
11141
|
-
token
|
|
11298
|
+
token,
|
|
11299
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
11142
11300
|
});
|
|
11143
11301
|
if (batchId !== null) {
|
|
11144
11302
|
recipientWallet.batchId = batchId;
|
|
@@ -11205,7 +11363,8 @@ var KnishIOClient = class {
|
|
|
11205
11363
|
const recipientWallets = recipients.map((recipient) => {
|
|
11206
11364
|
const recipientWallet = Wallet.create({
|
|
11207
11365
|
bundle: recipient.bundleHash,
|
|
11208
|
-
token
|
|
11366
|
+
token,
|
|
11367
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
11209
11368
|
});
|
|
11210
11369
|
if (recipient.batchId !== null && recipient.batchId !== void 0) {
|
|
11211
11370
|
recipientWallet.batchId = recipient.batchId;
|
|
@@ -11829,7 +11988,8 @@ var KnishIOClient = class {
|
|
|
11829
11988
|
secret: this.getSecret(),
|
|
11830
11989
|
bundle: this.getBundle(),
|
|
11831
11990
|
token,
|
|
11832
|
-
batchId
|
|
11991
|
+
batchId,
|
|
11992
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
11833
11993
|
});
|
|
11834
11994
|
await mutation.fillMolecule({
|
|
11835
11995
|
recipientWallet,
|
|
@@ -11897,7 +12057,8 @@ var KnishIOClient = class {
|
|
|
11897
12057
|
const recipientWallet = new Wallet({
|
|
11898
12058
|
secret: this.getSecret(),
|
|
11899
12059
|
bundle: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
11900
|
-
token
|
|
12060
|
+
token,
|
|
12061
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
11901
12062
|
});
|
|
11902
12063
|
await mutation.fillMolecule({
|
|
11903
12064
|
recipientWallet,
|
|
@@ -11974,7 +12135,8 @@ var KnishIOClient = class {
|
|
|
11974
12135
|
const newWallet = new Wallet({
|
|
11975
12136
|
secret: this.getSecret(),
|
|
11976
12137
|
bundle: this.getBundle(),
|
|
11977
|
-
token
|
|
12138
|
+
token,
|
|
12139
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
11978
12140
|
});
|
|
11979
12141
|
await mutation.fillMolecule(newWallet);
|
|
11980
12142
|
const response = await this.executeQuery(mutation);
|
|
@@ -12302,7 +12464,8 @@ var KnishIOClient = class {
|
|
|
12302
12464
|
this.setSecret(secret);
|
|
12303
12465
|
const wallet = new Wallet({
|
|
12304
12466
|
secret,
|
|
12305
|
-
token: "AUTH"
|
|
12467
|
+
token: "AUTH",
|
|
12468
|
+
mlKemParameterSet: this.getMlKemParameterSet()
|
|
12306
12469
|
});
|
|
12307
12470
|
const molecule = await this.createMolecule({
|
|
12308
12471
|
secret,
|
|
@@ -12702,7 +12865,7 @@ function createDefaultSecretStorage(options = {}) {
|
|
|
12702
12865
|
}
|
|
12703
12866
|
|
|
12704
12867
|
// src/index.ts
|
|
12705
|
-
var SDK_VERSION = "0.
|
|
12868
|
+
var SDK_VERSION = "1.0.0";
|
|
12706
12869
|
var SDK_NAME = "KnishIO-Client-TS";
|
|
12707
12870
|
var COMPATIBLE_SERVER_VERSIONS = [4, 5];
|
|
12708
12871
|
var SDK_INFO = {
|
|
@@ -12711,7 +12874,7 @@ var SDK_INFO = {
|
|
|
12711
12874
|
description: "TypeScript SDK for Knish.IO post-blockchain distributed ledger",
|
|
12712
12875
|
compatibleServerVersions: COMPATIBLE_SERVER_VERSIONS,
|
|
12713
12876
|
features: [
|
|
12714
|
-
"Post-quantum cryptography (XMSS, ML-
|
|
12877
|
+
"Post-quantum cryptography (XMSS, ML-KEM-1024)",
|
|
12715
12878
|
"Cross-platform compatibility",
|
|
12716
12879
|
"Type-safe APIs",
|
|
12717
12880
|
"DAG-based transaction processing",
|