@sekuire/sdk 0.1.19 → 0.1.22
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.esm.js +2 -1
- package/dist/index.js +12 -11
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -4,7 +4,7 @@ import { existsSync } from 'fs';
|
|
|
4
4
|
import fs$2, { readFile } from 'fs/promises';
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import path__default, { resolve, join } from 'path';
|
|
7
|
-
import * as nacl from 'tweetnacl';
|
|
7
|
+
import * as nacl$1 from 'tweetnacl';
|
|
8
8
|
import nacl__default from 'tweetnacl';
|
|
9
9
|
import * as blake3 from 'blake3';
|
|
10
10
|
import { v4 } from 'uuid';
|
|
@@ -1367,6 +1367,7 @@ function createBeacon(config) {
|
|
|
1367
1367
|
return new Beacon(config);
|
|
1368
1368
|
}
|
|
1369
1369
|
|
|
1370
|
+
const nacl = nacl__default ?? nacl$1;
|
|
1370
1371
|
class SekuireCrypto {
|
|
1371
1372
|
/**
|
|
1372
1373
|
* Generate a new Ed25519 keypair
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var axios = require('axios');
|
|
|
4
4
|
var fs = require('fs');
|
|
5
5
|
var fs$1 = require('fs/promises');
|
|
6
6
|
var path = require('path');
|
|
7
|
-
var nacl = require('tweetnacl');
|
|
7
|
+
var nacl$1 = require('tweetnacl');
|
|
8
8
|
var blake3 = require('blake3');
|
|
9
9
|
var uuid = require('uuid');
|
|
10
10
|
var require$$0 = require('url');
|
|
@@ -44,7 +44,7 @@ function _interopNamespaceDefault(e) {
|
|
|
44
44
|
|
|
45
45
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
46
46
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
47
|
-
var nacl__namespace = /*#__PURE__*/_interopNamespaceDefault(nacl);
|
|
47
|
+
var nacl__namespace = /*#__PURE__*/_interopNamespaceDefault(nacl$1);
|
|
48
48
|
var blake3__namespace = /*#__PURE__*/_interopNamespaceDefault(blake3);
|
|
49
49
|
var require$$2__namespace = /*#__PURE__*/_interopNamespaceDefault(require$$2);
|
|
50
50
|
var require$$3__namespace = /*#__PURE__*/_interopNamespaceDefault(require$$3);
|
|
@@ -1391,12 +1391,13 @@ function createBeacon(config) {
|
|
|
1391
1391
|
return new Beacon(config);
|
|
1392
1392
|
}
|
|
1393
1393
|
|
|
1394
|
+
const nacl = nacl$1 ?? nacl__namespace;
|
|
1394
1395
|
class SekuireCrypto {
|
|
1395
1396
|
/**
|
|
1396
1397
|
* Generate a new Ed25519 keypair
|
|
1397
1398
|
*/
|
|
1398
1399
|
static generateKeyPair() {
|
|
1399
|
-
const keyPair =
|
|
1400
|
+
const keyPair = nacl.sign.keyPair();
|
|
1400
1401
|
return {
|
|
1401
1402
|
publicKey: Buffer.from(keyPair.publicKey).toString("hex"),
|
|
1402
1403
|
privateKey: Buffer.from(keyPair.secretKey).toString("hex"),
|
|
@@ -1409,7 +1410,7 @@ class SekuireCrypto {
|
|
|
1409
1410
|
try {
|
|
1410
1411
|
const privateKey = SekuireCrypto.hexToBytes(privateKeyHex);
|
|
1411
1412
|
const messageBytes = typeof message === "string" ? Buffer.from(message, "utf8") : message;
|
|
1412
|
-
const signature =
|
|
1413
|
+
const signature = nacl.sign.detached(messageBytes, privateKey);
|
|
1413
1414
|
return Buffer.from(signature).toString("hex");
|
|
1414
1415
|
}
|
|
1415
1416
|
catch (error) {
|
|
@@ -1424,7 +1425,7 @@ class SekuireCrypto {
|
|
|
1424
1425
|
const messageBytes = typeof message === "string" ? Buffer.from(message, "utf8") : message;
|
|
1425
1426
|
const signature = SekuireCrypto.hexToBytes(signatureHex);
|
|
1426
1427
|
const publicKey = SekuireCrypto.hexToBytes(publicKeyHex);
|
|
1427
|
-
return
|
|
1428
|
+
return nacl.sign.detached.verify(messageBytes, signature, publicKey);
|
|
1428
1429
|
}
|
|
1429
1430
|
catch (error) {
|
|
1430
1431
|
throw new CryptoError(`Failed to verify signature: ${error.message}`);
|
|
@@ -1460,7 +1461,7 @@ class SekuireCrypto {
|
|
|
1460
1461
|
* Generate a cryptographically secure random nonce (32 bytes)
|
|
1461
1462
|
*/
|
|
1462
1463
|
static generateNonce() {
|
|
1463
|
-
const bytes =
|
|
1464
|
+
const bytes = nacl.randomBytes(32);
|
|
1464
1465
|
return Buffer.from(bytes).toString("hex");
|
|
1465
1466
|
}
|
|
1466
1467
|
/**
|
|
@@ -1569,7 +1570,7 @@ class AgentIdentity {
|
|
|
1569
1570
|
// tweetnacl expects a 64-byte secret key (seed + public key)
|
|
1570
1571
|
// or we generate a keypair from 32-byte seed
|
|
1571
1572
|
if (privateKeyBytes.length === 32) {
|
|
1572
|
-
const keyPair = nacl.sign.keyPair.fromSeed(privateKeyBytes);
|
|
1573
|
+
const keyPair = nacl$1.sign.keyPair.fromSeed(privateKeyBytes);
|
|
1573
1574
|
publicKey = SekuireCrypto.bytesToHex(keyPair.publicKey);
|
|
1574
1575
|
}
|
|
1575
1576
|
else if (privateKeyBytes.length === 64) {
|
|
@@ -1593,7 +1594,7 @@ class AgentIdentity {
|
|
|
1593
1594
|
let secretKey;
|
|
1594
1595
|
if (privateKeyBytes.length === 32) {
|
|
1595
1596
|
// 32-byte seed - derive full keypair
|
|
1596
|
-
const keyPair = nacl.sign.keyPair.fromSeed(privateKeyBytes);
|
|
1597
|
+
const keyPair = nacl$1.sign.keyPair.fromSeed(privateKeyBytes);
|
|
1597
1598
|
secretKey = keyPair.secretKey;
|
|
1598
1599
|
}
|
|
1599
1600
|
else if (privateKeyBytes.length === 64) {
|
|
@@ -1604,8 +1605,8 @@ class AgentIdentity {
|
|
|
1604
1605
|
throw new Error(`Invalid private key length: ${privateKeyBytes.length}. Expected 32 or 64 bytes.`);
|
|
1605
1606
|
}
|
|
1606
1607
|
// Sign the message (returns signature + message, we extract just signature)
|
|
1607
|
-
const signedMessage = nacl.sign(messageBytes, secretKey);
|
|
1608
|
-
const signature = signedMessage.slice(0, nacl.sign.signatureLength);
|
|
1608
|
+
const signedMessage = nacl$1.sign(messageBytes, secretKey);
|
|
1609
|
+
const signature = signedMessage.slice(0, nacl$1.sign.signatureLength);
|
|
1609
1610
|
return SekuireCrypto.bytesToHex(signature);
|
|
1610
1611
|
}
|
|
1611
1612
|
/**
|
|
@@ -1622,7 +1623,7 @@ class AgentIdentity {
|
|
|
1622
1623
|
const signedMessage = new Uint8Array(signatureBytes.length + messageBytes.length);
|
|
1623
1624
|
signedMessage.set(signatureBytes);
|
|
1624
1625
|
signedMessage.set(messageBytes, signatureBytes.length);
|
|
1625
|
-
const result = nacl.sign.open(signedMessage, publicKeyBytes);
|
|
1626
|
+
const result = nacl$1.sign.open(signedMessage, publicKeyBytes);
|
|
1626
1627
|
return result !== null;
|
|
1627
1628
|
}
|
|
1628
1629
|
}
|