@kynesyslabs/demosdk 2.1.13 → 2.1.15

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.
@@ -3,6 +3,12 @@ import { XMCoreTargetIdentityPayload, Web2CoreTargetIdentityPayload, GithubProof
3
3
  import { Demos } from "../websdk/demosclass";
4
4
  import { IKeyPair } from "../websdk/types/KeyPair";
5
5
  export default class Identities {
6
+ formats: {
7
+ web2: {
8
+ github: string[];
9
+ twitter: string[];
10
+ };
11
+ };
6
12
  /**
7
13
  * Create a web2 proof payload for use with web2 identity inference.
8
14
  *
@@ -9,6 +9,18 @@ const Cryptography_1 = require("../encryption/Cryptography");
9
9
  const node_forge_1 = __importDefault(require("node-forge"));
10
10
  const websdk_1 = require("../websdk");
11
11
  class Identities {
12
+ constructor() {
13
+ this.formats = {
14
+ web2: {
15
+ github: [
16
+ "https://gist.github.com",
17
+ "https://raw.githubusercontent.com",
18
+ "https://gist.githubusercontent.com",
19
+ ],
20
+ twitter: ["https://x.com", "https://twitter.com"],
21
+ },
22
+ };
23
+ }
12
24
  /**
13
25
  * Create a web2 proof payload for use with web2 identity inference.
14
26
  *
@@ -39,6 +51,14 @@ class Identities {
39
51
  * @returns The validity data of the identity transaction.
40
52
  */
41
53
  async inferIdentity(demos, context, payload) {
54
+ if (context === "web2") {
55
+ console.log;
56
+ if (!this.formats.web2[payload.context].some((format) => payload.proof.startsWith(format))) {
57
+ // construct informative error message
58
+ const errorMessage = `Invalid ${payload.context} proof format. Supported formats are: ${this.formats.web2[payload.context].join(", ")}`;
59
+ throw new Error(errorMessage);
60
+ }
61
+ }
42
62
  const tx = websdk_1.DemosTransactions.empty();
43
63
  const address = demos.getAddress();
44
64
  tx.content = {
@@ -1 +1 @@
1
- {"version":3,"file":"Identities.js","sourceRoot":"","sources":["../../../src/abstraction/Identities.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,8EAA8E;;;;;AAE9E,4DAAwD;AAcxD,4DAA8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EAAE,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;iBAC1C;aACJ;SACJ,CAAA;QAED,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC7C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CAAC,KAAY,EAAE,OAAgB;QAChD,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,OAAO,CAAC,CAAA;IACtE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,iBAAiB,CAAC,KAAY,EAAE,OAAgB;QAClD,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,mBAAmB,EAAE,OAAO,CAAC,CAAA;IACxE,CAAC;CACJ;AAzQD,6BAyQC"}
@@ -0,0 +1,130 @@
1
+ interface FalconKernel {
2
+ genkey: (seed?: Uint8Array) => FalconKeypair;
3
+ publicKeyCreate: (privateKey: Uint8Array) => Uint8Array;
4
+ sign: (message: string, privateKey: Uint8Array, salt?: Uint8Array) => Uint8Array;
5
+ verify: (signature: Uint8Array, message: string, publicKey: Uint8Array) => boolean;
6
+ algid: string;
7
+ genkeySeedByte: number;
8
+ skByte: number;
9
+ pkByte: number;
10
+ signByte: number;
11
+ signSaltByte: number;
12
+ signNonceByte: number;
13
+ }
14
+ interface FalconKeypair {
15
+ genkeySeed: Uint8Array;
16
+ sk: Uint8Array;
17
+ pk: Uint8Array;
18
+ }
19
+ export default class Falcon {
20
+ private kernel;
21
+ private keypair;
22
+ private algid;
23
+ constructor(algid?: string);
24
+ init(): Promise<void>;
25
+ genkey(seed?: Uint8Array): Promise<void>;
26
+ sign(message: string, salt?: Uint8Array): Promise<Uint8Array>;
27
+ verify(message: string, signature: Uint8Array, publicKey: Uint8Array): Promise<boolean>;
28
+ publicKeyCreate(privateKey: Uint8Array): Promise<Uint8Array>;
29
+ setKeypair(keypair: FalconKeypair): Promise<void>;
30
+ getPublicKey(): Promise<Uint8Array>;
31
+ getPrivateKey(): Promise<Uint8Array>;
32
+ getAlgid(): Promise<string>;
33
+ getKeypair(): Promise<FalconKeypair>;
34
+ getKernel(): Promise<FalconKernel>;
35
+ /**
36
+ * Convert a Uint8Array to a hex string
37
+ * @param array The Uint8Array to convert
38
+ * @returns A hex string representation of the Uint8Array
39
+ */
40
+ static uint8ArrayToHex(array: Uint8Array): string;
41
+ /**
42
+ * Convert a hex string to a Uint8Array
43
+ * @param hex The hex string to convert
44
+ * @returns A Uint8Array representation of the hex string
45
+ */
46
+ static hexToUint8Array(hex: string): Uint8Array;
47
+ /**
48
+ * Get the public key as a hex string
49
+ * @returns A hex string representation of the public key
50
+ */
51
+ getPublicKeyHex(): Promise<string>;
52
+ /**
53
+ * Get the private key as a hex string
54
+ * @returns A hex string representation of the private key
55
+ */
56
+ getPrivateKeyHex(): Promise<string>;
57
+ /**
58
+ * Sign a message and return the signature as a hex string
59
+ * @param message The message to sign
60
+ * @returns A hex string representation of the signature
61
+ */
62
+ signHex(message: string): Promise<string>;
63
+ /**
64
+ * Verify a signature provided as a hex string
65
+ * @param message The message that was signed
66
+ * @param signatureHex The signature as a hex string
67
+ * @returns True if the signature is valid, false otherwise
68
+ */
69
+ verifyHex(message: string, signatureHex: string, publicKeyHex: string): Promise<boolean>;
70
+ /**
71
+ * Create a public key from a private key provided as a hex string
72
+ * @param privateKeyHex The private key as a hex string
73
+ * @returns A hex string representation of the public key
74
+ */
75
+ publicKeyCreateHex(privateKeyHex: string): Promise<string>;
76
+ /**
77
+ * Set a private key from a hex string
78
+ * @param privateKeyHex The private key as a hex string
79
+ * @returns The public key as a hex string
80
+ */
81
+ setPrivateKeyHex(privateKeyHex: string): Promise<string>;
82
+ /**
83
+ * Convert a Uint8Array to a base64 string
84
+ * @param array The Uint8Array to convert
85
+ * @returns A base64 string representation of the Uint8Array
86
+ */
87
+ static uint8ArrayToBase64(array: Uint8Array): string;
88
+ /**
89
+ * Convert a base64 string to a Uint8Array
90
+ * @param base64 The base64 string to convert
91
+ * @returns A Uint8Array representation of the base64 string
92
+ */
93
+ static base64ToUint8Array(base64: string): Uint8Array;
94
+ /**
95
+ * Get the public key as a base64 string
96
+ * @returns A base64 string representation of the public key
97
+ */
98
+ getPublicKeyBase64(): Promise<string>;
99
+ /**
100
+ * Get the private key as a base64 string
101
+ * @returns A base64 string representation of the private key
102
+ */
103
+ getPrivateKeyBase64(): Promise<string>;
104
+ /**
105
+ * Sign a message and return the signature as a base64 string
106
+ * @param message The message to sign
107
+ * @returns A base64 string representation of the signature
108
+ */
109
+ signBase64(message: string): Promise<string>;
110
+ /**
111
+ * Verify a signature provided as a base64 string
112
+ * @param message The message that was signed
113
+ * @param signatureBase64 The signature as a base64 string
114
+ * @returns True if the signature is valid, false otherwise
115
+ */
116
+ verifyBase64(message: string, signatureBase64: string, publicKeyBase64: string): Promise<boolean>;
117
+ /**
118
+ * Create a public key from a private key provided as a base64 string
119
+ * @param privateKeyBase64 The private key as a base64 string
120
+ * @returns A base64 string representation of the public key
121
+ */
122
+ publicKeyCreateBase64(privateKeyBase64: string): Promise<string>;
123
+ /**
124
+ * Set a private key from a base64 string
125
+ * @param privateKeyBase64 The private key as a base64 string
126
+ * @returns The public key as a base64 string
127
+ */
128
+ setPrivateKeyBase64(privateKeyBase64: string): Promise<string>;
129
+ }
130
+ export {};
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const falcon_sign_1 = require("falcon-sign");
4
+ class Falcon {
5
+ constructor(algid) {
6
+ if (algid && (algid !== 'falcon512_n3_v1' && algid !== 'falcon1024_n3_v1')) {
7
+ throw new Error(`Invalid algorithm ID: ${algid}\nSupported algorithms: falcon512_n3_v1, falcon1024_n3_v1\nLeave blank for default: falcon512_n3_v1`);
8
+ }
9
+ this.algid = algid || 'falcon512_n3_v1';
10
+ }
11
+ async init() {
12
+ this.kernel = await (0, falcon_sign_1.getKernel)(this.algid);
13
+ }
14
+ // SECTION: Signing
15
+ async genkey(seed) {
16
+ if (seed) {
17
+ this.keypair = this.kernel.genkey(seed);
18
+ }
19
+ else {
20
+ this.keypair = this.kernel.genkey();
21
+ }
22
+ }
23
+ async sign(message, salt) {
24
+ if (salt) {
25
+ return this.kernel.sign(message, this.keypair.sk, salt);
26
+ }
27
+ else {
28
+ return this.kernel.sign(message, this.keypair.sk);
29
+ }
30
+ }
31
+ async verify(message, signature, publicKey) {
32
+ return this.kernel.verify(signature, message, publicKey);
33
+ }
34
+ async publicKeyCreate(privateKey) {
35
+ return this.kernel.publicKeyCreate(privateKey);
36
+ }
37
+ // SECTION: Setters
38
+ async setKeypair(keypair) {
39
+ this.keypair = keypair;
40
+ }
41
+ // SECTION: Getters
42
+ async getPublicKey() {
43
+ return this.keypair.pk;
44
+ }
45
+ async getPrivateKey() {
46
+ return this.keypair.sk;
47
+ }
48
+ async getAlgid() {
49
+ return this.algid;
50
+ }
51
+ async getKeypair() {
52
+ return this.keypair;
53
+ }
54
+ async getKernel() {
55
+ return this.kernel;
56
+ }
57
+ // Helper methods for hex string conversion
58
+ /**
59
+ * Convert a Uint8Array to a hex string
60
+ * @param array The Uint8Array to convert
61
+ * @returns A hex string representation of the Uint8Array
62
+ */
63
+ static uint8ArrayToHex(array) {
64
+ return Array.from(array)
65
+ .map(b => b.toString(16).padStart(2, '0'))
66
+ .join('');
67
+ }
68
+ /**
69
+ * Convert a hex string to a Uint8Array
70
+ * @param hex The hex string to convert
71
+ * @returns A Uint8Array representation of the hex string
72
+ */
73
+ static hexToUint8Array(hex) {
74
+ // Remove any non-hex characters
75
+ hex = hex.replace(/[^0-9a-fA-F]/g, '');
76
+ // Ensure the hex string has an even length
77
+ if (hex.length % 2 !== 0) {
78
+ hex = '0' + hex;
79
+ }
80
+ const array = new Uint8Array(hex.length / 2);
81
+ for (let i = 0; i < hex.length; i += 2) {
82
+ array[i / 2] = parseInt(hex.substring(i, i + 2), 16);
83
+ }
84
+ return array;
85
+ }
86
+ /**
87
+ * Get the public key as a hex string
88
+ * @returns A hex string representation of the public key
89
+ */
90
+ async getPublicKeyHex() {
91
+ const publicKey = await this.getPublicKey();
92
+ return Falcon.uint8ArrayToHex(publicKey);
93
+ }
94
+ /**
95
+ * Get the private key as a hex string
96
+ * @returns A hex string representation of the private key
97
+ */
98
+ async getPrivateKeyHex() {
99
+ const privateKey = await this.getPrivateKey();
100
+ return Falcon.uint8ArrayToHex(privateKey);
101
+ }
102
+ /**
103
+ * Sign a message and return the signature as a hex string
104
+ * @param message The message to sign
105
+ * @returns A hex string representation of the signature
106
+ */
107
+ async signHex(message) {
108
+ const signature = await this.sign(message);
109
+ return Falcon.uint8ArrayToHex(signature);
110
+ }
111
+ /**
112
+ * Verify a signature provided as a hex string
113
+ * @param message The message that was signed
114
+ * @param signatureHex The signature as a hex string
115
+ * @returns True if the signature is valid, false otherwise
116
+ */
117
+ async verifyHex(message, signatureHex, publicKeyHex) {
118
+ const signature = Falcon.hexToUint8Array(signatureHex);
119
+ const publicKey = Falcon.hexToUint8Array(publicKeyHex);
120
+ return this.verify(message, signature, publicKey);
121
+ }
122
+ /**
123
+ * Create a public key from a private key provided as a hex string
124
+ * @param privateKeyHex The private key as a hex string
125
+ * @returns A hex string representation of the public key
126
+ */
127
+ async publicKeyCreateHex(privateKeyHex) {
128
+ const privateKey = Falcon.hexToUint8Array(privateKeyHex);
129
+ const publicKey = await this.publicKeyCreate(privateKey);
130
+ return Falcon.uint8ArrayToHex(publicKey);
131
+ }
132
+ /**
133
+ * Set a private key from a hex string
134
+ * @param privateKeyHex The private key as a hex string
135
+ * @returns The public key as a hex string
136
+ */
137
+ async setPrivateKeyHex(privateKeyHex) {
138
+ const privateKey = Falcon.hexToUint8Array(privateKeyHex);
139
+ const publicKey = await this.publicKeyCreate(privateKey);
140
+ // Update the keypair
141
+ this.keypair = {
142
+ genkeySeed: new Uint8Array(0), // We don't have the seed
143
+ sk: privateKey,
144
+ pk: publicKey
145
+ };
146
+ return Falcon.uint8ArrayToHex(publicKey);
147
+ }
148
+ /**
149
+ * Convert a Uint8Array to a base64 string
150
+ * @param array The Uint8Array to convert
151
+ * @returns A base64 string representation of the Uint8Array
152
+ */
153
+ static uint8ArrayToBase64(array) {
154
+ return Buffer.from(array).toString('base64');
155
+ }
156
+ /**
157
+ * Convert a base64 string to a Uint8Array
158
+ * @param base64 The base64 string to convert
159
+ * @returns A Uint8Array representation of the base64 string
160
+ */
161
+ static base64ToUint8Array(base64) {
162
+ return Buffer.from(base64, 'base64');
163
+ }
164
+ /**
165
+ * Get the public key as a base64 string
166
+ * @returns A base64 string representation of the public key
167
+ */
168
+ async getPublicKeyBase64() {
169
+ const publicKey = await this.getPublicKey();
170
+ return Falcon.uint8ArrayToBase64(publicKey);
171
+ }
172
+ /**
173
+ * Get the private key as a base64 string
174
+ * @returns A base64 string representation of the private key
175
+ */
176
+ async getPrivateKeyBase64() {
177
+ const privateKey = await this.getPrivateKey();
178
+ return Falcon.uint8ArrayToBase64(privateKey);
179
+ }
180
+ /**
181
+ * Sign a message and return the signature as a base64 string
182
+ * @param message The message to sign
183
+ * @returns A base64 string representation of the signature
184
+ */
185
+ async signBase64(message) {
186
+ const signature = await this.sign(message);
187
+ return Falcon.uint8ArrayToBase64(signature);
188
+ }
189
+ /**
190
+ * Verify a signature provided as a base64 string
191
+ * @param message The message that was signed
192
+ * @param signatureBase64 The signature as a base64 string
193
+ * @returns True if the signature is valid, false otherwise
194
+ */
195
+ async verifyBase64(message, signatureBase64, publicKeyBase64) {
196
+ const signature = Falcon.base64ToUint8Array(signatureBase64);
197
+ const publicKey = Falcon.base64ToUint8Array(publicKeyBase64);
198
+ return this.verify(message, signature, publicKey);
199
+ }
200
+ /**
201
+ * Create a public key from a private key provided as a base64 string
202
+ * @param privateKeyBase64 The private key as a base64 string
203
+ * @returns A base64 string representation of the public key
204
+ */
205
+ async publicKeyCreateBase64(privateKeyBase64) {
206
+ const privateKey = Falcon.base64ToUint8Array(privateKeyBase64);
207
+ const publicKey = await this.publicKeyCreate(privateKey);
208
+ return Falcon.uint8ArrayToBase64(publicKey);
209
+ }
210
+ /**
211
+ * Set a private key from a base64 string
212
+ * @param privateKeyBase64 The private key as a base64 string
213
+ * @returns The public key as a base64 string
214
+ */
215
+ async setPrivateKeyBase64(privateKeyBase64) {
216
+ const privateKey = Falcon.base64ToUint8Array(privateKeyBase64);
217
+ const publicKey = await this.publicKeyCreate(privateKey);
218
+ // Update the keypair
219
+ this.keypair = {
220
+ genkeySeed: new Uint8Array(0), // We don't have the seed
221
+ sk: privateKey,
222
+ pk: publicKey
223
+ };
224
+ return Falcon.uint8ArrayToBase64(publicKey);
225
+ }
226
+ }
227
+ exports.default = Falcon;
228
+ //# sourceMappingURL=falcon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"falcon.js","sourceRoot":"","sources":["../../../../../src/encryption/PQC/falconts/falcon.ts"],"names":[],"mappings":";;AAAA,6CAAwC;AAuBxC,MAAqB,MAAM;IAKvB,YAAY,KAAc;QACtB,IAAI,KAAK,IAAI,CAAC,KAAK,KAAK,iBAAiB,IAAI,KAAK,KAAK,kBAAkB,CAAC,EAAE,CAAC;YACzE,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,qGAAqG,CAAC,CAAC;QACzJ,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,iBAAiB,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,IAAI;QACN,IAAI,CAAC,MAAM,GAAG,MAAM,IAAA,uBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED,mBAAmB;IAEnB,KAAK,CAAC,MAAM,CAAC,IAAiB;QAC1B,IAAI,IAAI,EAAE,CAAC;YACP,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,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C;QACzD,OAAO,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,mBAAmB,CAAC,gBAAwB;QAC9C,MAAM,UAAU,GAAG,MAAM,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;QAC/D,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QAEzD,qBAAqB;QACrB,IAAI,CAAC,OAAO,GAAG;YACX,UAAU,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,yBAAyB;YACxD,EAAE,EAAE,UAAU;YACd,EAAE,EAAE,SAAS;SAChB,CAAC;QAEF,OAAO,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;CACJ;AArQD,yBAqQC"}
@@ -0,0 +1,3 @@
1
+ export { default as Falcon } from './falcon';
2
+ export { uint8ArrayToMnemonic, mnemonicToUint8Array, validateMnemonic, generateMnemonic } from './mnemonic';
3
+ export { wordList } from './wordlist';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.wordList = exports.generateMnemonic = exports.validateMnemonic = exports.mnemonicToUint8Array = exports.uint8ArrayToMnemonic = exports.Falcon = void 0;
7
+ // Export Falcon class
8
+ var falcon_1 = require("./falcon");
9
+ Object.defineProperty(exports, "Falcon", { enumerable: true, get: function () { return __importDefault(falcon_1).default; } });
10
+ // Export mnemonic functions
11
+ var mnemonic_1 = require("./mnemonic");
12
+ Object.defineProperty(exports, "uint8ArrayToMnemonic", { enumerable: true, get: function () { return mnemonic_1.uint8ArrayToMnemonic; } });
13
+ Object.defineProperty(exports, "mnemonicToUint8Array", { enumerable: true, get: function () { return mnemonic_1.mnemonicToUint8Array; } });
14
+ Object.defineProperty(exports, "validateMnemonic", { enumerable: true, get: function () { return mnemonic_1.validateMnemonic; } });
15
+ Object.defineProperty(exports, "generateMnemonic", { enumerable: true, get: function () { return mnemonic_1.generateMnemonic; } });
16
+ // Export word list
17
+ var wordlist_1 = require("./wordlist");
18
+ Object.defineProperty(exports, "wordList", { enumerable: true, get: function () { return wordlist_1.wordList; } });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/encryption/PQC/falconts/index.ts"],"names":[],"mappings":";;;;;;AAAA,sBAAsB;AACtB,mCAA6C;AAApC,iHAAA,OAAO,OAAU;AAE1B,4BAA4B;AAC5B,uCAKoB;AAJlB,gHAAA,oBAAoB,OAAA;AACpB,gHAAA,oBAAoB,OAAA;AACpB,4GAAA,gBAAgB,OAAA;AAChB,4GAAA,gBAAgB,OAAA;AAGlB,mBAAmB;AACnB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Custom mnemonic implementation for Falcon keys.
3
+ * This implementation is designed to work with Falcon's key sizes and doesn't rely on BIP39.
4
+ */
5
+ /**
6
+ * Convert a Uint8Array to a mnemonic phrase
7
+ * @param data The Uint8Array to convert
8
+ * @returns A mnemonic phrase (12 words)
9
+ */
10
+ export declare function uint8ArrayToMnemonic(data: Uint8Array): string;
11
+ /**
12
+ * Convert a mnemonic phrase to a Uint8Array
13
+ * @param mnemonic The mnemonic phrase
14
+ * @returns A Uint8Array of 48 bytes (384 bits) suitable for Falcon key generation
15
+ */
16
+ export declare function mnemonicToUint8Array(mnemonic: string): Uint8Array;
17
+ /**
18
+ * Validate a mnemonic phrase
19
+ * @param mnemonic The mnemonic phrase to validate
20
+ * @returns True if the mnemonic is valid, false otherwise
21
+ */
22
+ export declare function validateMnemonic(mnemonic: string): boolean;
23
+ /**
24
+ * Generate a random mnemonic phrase
25
+ * @returns A random mnemonic phrase
26
+ */
27
+ export declare function generateMnemonic(): string;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uint8ArrayToMnemonic = uint8ArrayToMnemonic;
4
+ exports.mnemonicToUint8Array = mnemonicToUint8Array;
5
+ exports.validateMnemonic = validateMnemonic;
6
+ exports.generateMnemonic = generateMnemonic;
7
+ const wordlist_1 = require("./wordlist");
8
+ const crypto_1 = require("crypto");
9
+ /**
10
+ * Custom mnemonic implementation for Falcon keys.
11
+ * This implementation is designed to work with Falcon's key sizes and doesn't rely on BIP39.
12
+ */
13
+ /**
14
+ * Convert a Uint8Array to a mnemonic phrase
15
+ * @param data The Uint8Array to convert
16
+ * @returns A mnemonic phrase (12 words)
17
+ */
18
+ function uint8ArrayToMnemonic(data) {
19
+ // We'll use 12 words, each representing 11 bits of entropy
20
+ // This gives us 132 bits of entropy, which is sufficient for Falcon keys
21
+ // Convert the Uint8Array to a binary string
22
+ let binary = '';
23
+ for (let i = 0; i < data.length; i++) {
24
+ binary += data[i].toString(2).padStart(8, '0');
25
+ }
26
+ // Ensure we have enough bits
27
+ while (binary.length < 132) {
28
+ binary += '0';
29
+ }
30
+ // Take the first 132 bits
31
+ binary = binary.substring(0, 132);
32
+ // Split into 11-bit chunks
33
+ const chunks = [];
34
+ for (let i = 0; i < 12; i++) {
35
+ chunks.push(binary.substring(i * 11, (i + 1) * 11));
36
+ }
37
+ // Convert each chunk to a decimal number and use it to select a word
38
+ const words = [];
39
+ for (const chunk of chunks) {
40
+ const index = parseInt(chunk, 2);
41
+ words.push(wordlist_1.wordList[index % wordlist_1.wordList.length]);
42
+ }
43
+ return words.join(' ');
44
+ }
45
+ /**
46
+ * Convert a mnemonic phrase to a Uint8Array
47
+ * @param mnemonic The mnemonic phrase
48
+ * @returns A Uint8Array of 48 bytes (384 bits) suitable for Falcon key generation
49
+ */
50
+ function mnemonicToUint8Array(mnemonic) {
51
+ // Split the mnemonic into words
52
+ const words = mnemonic.trim().split(/\s+/);
53
+ if (words.length !== 12) {
54
+ throw new Error('Invalid mnemonic phrase: must contain exactly 12 words');
55
+ }
56
+ // Convert each word to its index in the word list
57
+ const indices = [];
58
+ for (const word of words) {
59
+ const index = wordlist_1.wordList.indexOf(word);
60
+ if (index === -1) {
61
+ throw new Error(`Invalid word in mnemonic: ${word}`);
62
+ }
63
+ indices.push(index);
64
+ }
65
+ // Convert indices to binary
66
+ let binary = '';
67
+ for (const index of indices) {
68
+ binary += index.toString(2).padStart(11, '0');
69
+ }
70
+ // Convert binary to initial entropy bytes
71
+ const entropyBytes = [];
72
+ for (let i = 0; i < binary.length; i += 8) {
73
+ const byte = binary.substring(i, i + 8);
74
+ entropyBytes.push(parseInt(byte, 2));
75
+ }
76
+ // Create initial entropy Uint8Array
77
+ const entropy = new Uint8Array(entropyBytes);
78
+ // Use SHA-512 to expand the entropy to 48 bytes
79
+ const hash = (0, crypto_1.createHash)('sha512');
80
+ hash.update(entropy);
81
+ const expandedEntropy = new Uint8Array(hash.digest().buffer.slice(0, 48));
82
+ return expandedEntropy;
83
+ }
84
+ /**
85
+ * Validate a mnemonic phrase
86
+ * @param mnemonic The mnemonic phrase to validate
87
+ * @returns True if the mnemonic is valid, false otherwise
88
+ */
89
+ function validateMnemonic(mnemonic) {
90
+ try {
91
+ mnemonicToUint8Array(mnemonic);
92
+ return true;
93
+ }
94
+ catch (error) {
95
+ return false;
96
+ }
97
+ }
98
+ /**
99
+ * Generate a random mnemonic phrase
100
+ * @returns A random mnemonic phrase
101
+ */
102
+ function generateMnemonic() {
103
+ // Generate a random Uint8Array
104
+ const randomBytes = new Uint8Array(16); // 128 bits
105
+ crypto.getRandomValues(randomBytes);
106
+ // Convert to mnemonic
107
+ return uint8ArrayToMnemonic(randomBytes);
108
+ }
109
+ //# sourceMappingURL=mnemonic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mnemonic.js","sourceRoot":"","sources":["../../../../../src/encryption/PQC/falconts/mnemonic.ts"],"names":[],"mappings":";;AAaA,oDAgCC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,oCAAoC;IACpC,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;IAE7C,gDAAgD;IAChD,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAE1E,OAAO,eAAe,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,QAAgB;IAC7C,IAAI,CAAC;QACD,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,SAAgB,gBAAgB;IAC5B,+BAA+B;IAC/B,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW;IACnD,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IAEpC,sBAAsB;IACtB,OAAO,oBAAoB,CAAC,WAAW,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A list of 2048 common English words for mnemonic generation.
3
+ * This is a subset of the BIP39 word list, but we're using it differently.
4
+ */
5
+ export declare const wordList: string[];