Comparing version 2.2.0 to 2.3.0
# Changelog | ||
## [2.3.0] | ||
### Changed | ||
- Simplified registry API. | ||
## [2.2.0] | ||
@@ -4,0 +10,0 @@ |
import { SkynetClient } from "./client"; | ||
import { PublicKey, Signature } from "./crypto"; | ||
import { PublicKey, SecretKey, Signature } from "./crypto"; | ||
export declare type RegistryEntry = { | ||
@@ -19,4 +19,4 @@ datakey: string; | ||
*/ | ||
export declare function getEntry(this: SkynetClient, publickey: PublicKey, datakey: string, customOptions?: {}): Promise<SignedRegistryEntry | null>; | ||
export declare function setEntry(this: SkynetClient, publickey: PublicKey, datakey: string, entry: RegistryEntry, signature: Signature, customOptions?: {}): Promise<void>; | ||
export declare function getEntry(this: SkynetClient, publicKey: PublicKey, datakey: string, customOptions?: {}): Promise<SignedRegistryEntry | null>; | ||
export declare function setEntry(this: SkynetClient, privateKey: SecretKey, datakey: string, entry: RegistryEntry, customOptions?: {}): Promise<void>; | ||
//# sourceMappingURL=registry.d.ts.map |
@@ -51,2 +51,3 @@ "use strict"; | ||
exports.setEntry = exports.getEntry = void 0; | ||
var node_forge_1 = require("node-forge"); | ||
var utils_1 = require("./utils"); | ||
@@ -63,6 +64,6 @@ var buffer_1 = require("buffer"); | ||
*/ | ||
function getEntry(publickey, datakey, customOptions) { | ||
function getEntry(publicKey, datakey, customOptions) { | ||
if (customOptions === void 0) { customOptions = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var opts, response, err_1; | ||
var opts, response, err_1, entry; | ||
return __generator(this, function (_a) { | ||
@@ -76,3 +77,3 @@ switch (_a.label) { | ||
return [4 /*yield*/, this.executeRequest(__assign(__assign({}, opts), { method: "get", query: { | ||
publickey: "ed25519:" + publickey.toString("hex"), | ||
publickey: "ed25519:" + publicKey.toString("hex"), | ||
datakey: buffer_1.Buffer.from(crypto_1.HashDataKey(datakey)).toString("hex") | ||
@@ -88,14 +89,23 @@ }, timeout: opts.timeout }))]; | ||
case 4: | ||
if (response.status === 200) { | ||
return [2 /*return*/, { | ||
entry: { | ||
datakey: datakey, | ||
data: buffer_1.Buffer.from(utils_1.hexToUint8Array(response.data.data)).toString(), | ||
// TODO: Handle uint64 properly. | ||
revision: parseInt(response.data.revision, 10) | ||
}, | ||
signature: buffer_1.Buffer.from(utils_1.hexToUint8Array(response.data.signature)) | ||
}]; | ||
if (response.status !== 200) { | ||
return [2 /*return*/, null]; | ||
} | ||
return [2 /*return*/, null]; | ||
entry = { | ||
entry: { | ||
datakey: datakey, | ||
data: buffer_1.Buffer.from(utils_1.hexToUint8Array(response.data.data)).toString(), | ||
// TODO: Handle uint64 properly. | ||
revision: parseInt(response.data.revision, 10) | ||
}, | ||
signature: buffer_1.Buffer.from(utils_1.hexToUint8Array(response.data.signature)) | ||
}; | ||
if (entry && | ||
!node_forge_1.pki.ed25519.verify({ | ||
message: crypto_1.HashRegistryEntry(entry.entry), | ||
signature: entry.signature, | ||
publicKey: publicKey | ||
})) { | ||
throw new Error("could not verify signature from retrieved, signed registry entry -- possible corrupted entry"); | ||
} | ||
return [2 /*return*/, entry]; | ||
} | ||
@@ -106,6 +116,6 @@ }); | ||
exports.getEntry = getEntry; | ||
function setEntry(publickey, datakey, entry, signature, customOptions) { | ||
function setEntry(privateKey, datakey, entry, customOptions) { | ||
if (customOptions === void 0) { customOptions = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var opts, data; | ||
var opts, signature, publickey, data; | ||
return __generator(this, function (_a) { | ||
@@ -115,2 +125,7 @@ switch (_a.label) { | ||
opts = __assign(__assign(__assign({}, defaultRegistryOptions), this.customOptions), customOptions); | ||
signature = node_forge_1.pki.ed25519.sign({ | ||
message: crypto_1.HashRegistryEntry(entry), | ||
privateKey: privateKey | ||
}); | ||
publickey = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKey }); | ||
data = { | ||
@@ -117,0 +132,0 @@ publickey: { |
@@ -52,3 +52,2 @@ "use strict"; | ||
var node_forge_1 = require("node-forge"); | ||
var crypto_1 = require("./crypto"); | ||
var utils_1 = require("./utils"); | ||
@@ -89,3 +88,3 @@ /** | ||
return __awaiter(this, void 0, void 0, function () { | ||
var opts, file, skylink, publicKey, entry_1, err_1, entry, signature; | ||
var opts, file, skylink, entry_1, publicKey, err_1, entry; | ||
return __generator(this, function (_a) { | ||
@@ -99,7 +98,7 @@ switch (_a.label) { | ||
skylink = (_a.sent()).skylink; | ||
publicKey = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKey }); | ||
if (!!revision) return [3 /*break*/, 6]; | ||
if (!!revision) return [3 /*break*/, 5]; | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 4, , 5]); | ||
publicKey = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKey }); | ||
return [4 /*yield*/, this.registry.getEntry(publicKey, dataKey, opts)]; | ||
@@ -115,13 +114,2 @@ case 3: | ||
case 5: | ||
// Verify here if we fetched the entry earlier. | ||
if (entry_1 && | ||
!node_forge_1.pki.ed25519.verify({ | ||
message: crypto_1.HashRegistryEntry(entry_1.entry), | ||
signature: entry_1.signature, | ||
publicKey: publicKey | ||
})) { | ||
throw new Error("could not verify signature from retrieved, signed registry entry -- possible corrupted entry"); | ||
} | ||
_a.label = 6; | ||
case 6: | ||
entry = { | ||
@@ -132,9 +120,5 @@ datakey: dataKey, | ||
}; | ||
signature = node_forge_1.pki.ed25519.sign({ | ||
message: crypto_1.HashRegistryEntry(entry), | ||
privateKey: privateKey | ||
}); | ||
// update the registry | ||
return [4 /*yield*/, this.registry.setEntry(publicKey, dataKey, entry, signature)]; | ||
case 7: | ||
return [4 /*yield*/, this.registry.setEntry(privateKey, dataKey, entry)]; | ||
case 6: | ||
// update the registry | ||
@@ -141,0 +125,0 @@ _a.sent(); |
{ | ||
"name": "skynet-js", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Sia Skynet Javascript Client", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78185
1244