Skip to content

Commit

Permalink
remove did-jwt dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianekc committed Feb 21, 2024
1 parent bb4a194 commit 8e08418
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 92 deletions.
5 changes: 3 additions & 2 deletions oydid-js/dist/oydid.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.hexToMulti = exports.didAuth = exports.verify = exports.sign = exports.decrypt = exports.encrypt = exports.deactivate = exports.update = exports.read = exports.create = exports.DEFAULT_ENCODING = exports.DEFAULT_DIGEST = void 0;
const did_jwt_1 = __importDefault(require("did-jwt"));
// import didJWT from 'did-jwt';
const axios_1 = __importDefault(require("axios"));
const base58_1 = require("multiformats/bases/base58");
exports.DEFAULT_DIGEST = "sha2-256";
Expand Down Expand Up @@ -167,7 +167,8 @@ exports.didAuth = didAuth;
* @returns base58btc Multiformat encoded object
*/
const hexToMulti = (hexKey, options) => __awaiter(void 0, void 0, void 0, function* () {
const keyBytes = did_jwt_1.default.hexToBytes(hexKey);
const keyBytes = Buffer.from(hexKey, "hex");
// const keyBytes = didJWT.hexToBytes(hexKey);
const multiformatKey = base58_1.base58btc.encode(keyBytes);
return multiformatKey;
});
Expand Down
3 changes: 2 additions & 1 deletion oydid-js/dist/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ const cipher_message = {
value: "82ba7d8ec5800786d9ae1414cd70ba864f438051085be7834cbde39d093684f9f90a0d9a1ccd9b7337baa2e00a94ccbaf29b70acd391471b0a9cd27731cbd214ea98e1c5d11670e37a6b6b0eb1",
nonce: "9266f52178bfa1df25fa16b6fb984e67e02c0a223ee34b33"
};
const private_key_hex = "001320d119a71ed168aab7f4bd0a686e7bf2c32ac243c1463642ebaa7d40a93ecb4aa3";
const private_key_hex = "001320d019a71ed168aab7f4bd0a686e7bf2c32ac243c1463642ebaa7d40a93ecb4aa3";
const private_key = (0, oydid_1.hexToMulti)(private_key_hex).then(key => {
// console.log(key);
(0, oydid_1.decrypt)(cipher_message, key).then(response => {
console.log(response.toString());
});
Expand Down
109 changes: 25 additions & 84 deletions oydid-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions oydid-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oydid",
"version": "0.0.8",
"version": "0.0.9",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand All @@ -13,12 +13,12 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@types/node": "^20.11.19",
"multibase": "^4.0.6",
"typescript": "^5.2.2"
},
"dependencies": {
"axios": "^1.5.0",
"did-jwt": "^8.0.0",
"multiformats": "^9.9.0"
}
}
5 changes: 3 additions & 2 deletions oydid-js/src/oydid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import didJWT from 'did-jwt';
// import didJWT from 'did-jwt';
import axios from 'axios';
import { base58btc } from 'multiformats/bases/base58';

Expand Down Expand Up @@ -272,7 +272,8 @@ export const didAuth = async(did: string, key: string, regapi_url: string) : Pro
* @returns base58btc Multiformat encoded object
*/
export const hexToMulti = async(hexKey: string, options?: Partial<ReadOptions>) : Promise<string> => {
const keyBytes = didJWT.hexToBytes(hexKey);
const keyBytes = Buffer.from(hexKey, "hex");
// const keyBytes = didJWT.hexToBytes(hexKey);
const multiformatKey = base58btc.encode(keyBytes);
return multiformatKey;
}
3 changes: 2 additions & 1 deletion oydid-js/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const cipher_message = {
value: "82ba7d8ec5800786d9ae1414cd70ba864f438051085be7834cbde39d093684f9f90a0d9a1ccd9b7337baa2e00a94ccbaf29b70acd391471b0a9cd27731cbd214ea98e1c5d11670e37a6b6b0eb1",
nonce: "9266f52178bfa1df25fa16b6fb984e67e02c0a223ee34b33"
} as CipherMessage;
const private_key_hex = "001320d119a71ed168aab7f4bd0a686e7bf2c32ac243c1463642ebaa7d40a93ecb4aa3";
const private_key_hex = "001320d019a71ed168aab7f4bd0a686e7bf2c32ac243c1463642ebaa7d40a93ecb4aa3";

const private_key = hexToMulti(private_key_hex).then(key => {
// console.log(key);
decrypt(cipher_message, key).then(response => {
console.log(response.toString());
})
Expand Down

0 comments on commit 8e08418

Please sign in to comment.