Skip to content

Commit

Permalink
PharmaLedger-IMI/epi-workspace#888 implemented PathKeyMapping and Wal…
Browse files Browse the repository at this point in the history
…letDBEnclaveHandler
  • Loading branch information
skutner committed Oct 24, 2022
1 parent 3b5d057 commit 0182290
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
1 change: 1 addition & 0 deletions lib/CryptoAlgorithms/CryptoAlgorithmsRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ CryptoAlgorithmsRegistry.prototype.getCryptoFunction = getCryptoFunction;
CryptoAlgorithmsRegistry.prototype.registerCryptoInterface = registerCryptoInterface;

CryptoAlgorithmsRegistry.prototype.registerCryptoInterface(SSITypes.SEED_SSI, 'v0', new SeedSSICryptoAlgorithms());
CryptoAlgorithmsRegistry.prototype.registerCryptoInterface(SSITypes.PATH_SSI, 'v0', new CryptoAlgorithmsMixin());
CryptoAlgorithmsRegistry.prototype.registerCryptoInterface(SSITypes.WALLET_SSI, 'v0', new SeedSSICryptoAlgorithms());
CryptoAlgorithmsRegistry.prototype.registerCryptoInterface(SSITypes.SREAD_SSI, 'v0', new CryptoAlgorithmsMixin());
CryptoAlgorithmsRegistry.prototype.registerCryptoInterface(SSITypes.SZERO_ACCESS_SSI, 'v0', new CryptoAlgorithmsMixin());
Expand Down
67 changes: 28 additions & 39 deletions lib/KeySSIs/SeedSSIs/PathKeySSI.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,41 @@ function PathKeySSI(enclave, identifier) {

self.setCanSign(true);

self.initialize = function (dlDomain, path, vn, hint, callback) {
if (typeof vn === "function") {
callback = vn;
vn = 'v0';
}
self.derive = function (callback) {
const splitSpecificString = self.getSpecificString().split("/");
const slot = splitSpecificString[0];
const path = splitSpecificString[1];

if (typeof hint === "function") {
callback = hint;
hint = undefined;
const __getPrivateKeyForSlot = () => {
enclave.getPrivateKeyForSlot(slot, (err, _privateKey)=>{
if (err) {
return callback(err);
}

privateKey = _privateKey;
privateKey = cryptoRegistry.getHashFunction(self)(`${path}${privateKey}`);
privateKey = cryptoRegistry.getDecodingFunction(self)(privateKey);
const seedSpecificString = cryptoRegistry.getBase64EncodingFunction(self)(privateKey);
const seedSSI = SeedSSI.createSeedSSI(enclave);
seedSSI.load(SSITypes.SEED_SSI, self.getDLDomain(), seedSpecificString, undefined, self.getVn(), self.getHint());
callback(undefined, seedSSI);
});
}

const slot = path.split("/")[0];
enclave.getPrivateKeyForSlot(slot, (err, _privateKey) => {
if (err) {
return OpenDSUSafeCallback(callback)(createOpenDSUErrorWrapper(`Failed to get privateKey`, err));
}

privateKey = _privateKey;
if (typeof enclave === "undefined") {
require("opendsu").loadAPI("sc").getMainEnclave((err, mainEnclave)=>{
if (err) {
return callback(err);
}

self.load(SSITypes.PATH_SSI, dlDomain, path, '', vn, hint);
if (callback) {
callback(undefined, self);
}
})
enclave = mainEnclave;
__getPrivateKeyForSlot();
})

self.initialize = function () {
throw Error("KeySSI already initialized");
return;
}
};

self.derive = function (callback) {
const splitSpecificString = self.getSpecificString().split("/");
const slot = splitSpecificString[0];
const path = splitSpecificString[1];
enclave.getPrivateKeyForSlot(slot, (err, _privateKey)=>{
if (err) {
return callback(err);
}

privateKey = _privateKey;
privateKey = cryptoRegistry.getHashFunction(self)(`${path}${privateKey}`);
const seedSpecificString = cryptoRegistry.getBase64EncodingFunction(self)(privateKey);
const seedSSI = SeedSSI.createSeedSSI(enclave);
seedSSI.load(SSITypes.SEED_SSI, self.getDLDomain(), seedSpecificString, undefined, self.getVn(), self.getHint());
callback(undefined, seedSSI);
})
__getPrivateKeyForSlot();
};

self.getPrivateKey = function (format) {
Expand Down

0 comments on commit 0182290

Please sign in to comment.