@dfns/blockchain-integration
Advanced tools
Comparing version 2.1.1 to 2.2.1
export { createWalletLambdaHandler } from "./lambda-handler"; | ||
export { SigningGroup, createSigningGroup, SigningGroupNotInitializedError } from './signing-group'; | ||
export { SigningGroup, SigningGroupNotInitializedError } from "./signing-group"; | ||
export { WalletInterface } from "./types/wallet"; | ||
export { ApiClient } from "./api-client"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SigningGroupNotInitializedError = exports.createSigningGroup = exports.SigningGroup = exports.createWalletLambdaHandler = void 0; | ||
exports.ApiClient = exports.SigningGroupNotInitializedError = exports.SigningGroup = exports.createWalletLambdaHandler = void 0; | ||
var lambda_handler_1 = require("./lambda-handler"); | ||
@@ -8,3 +8,4 @@ Object.defineProperty(exports, "createWalletLambdaHandler", { enumerable: true, get: function () { return lambda_handler_1.createWalletLambdaHandler; } }); | ||
Object.defineProperty(exports, "SigningGroup", { enumerable: true, get: function () { return signing_group_1.SigningGroup; } }); | ||
Object.defineProperty(exports, "createSigningGroup", { enumerable: true, get: function () { return signing_group_1.createSigningGroup; } }); | ||
Object.defineProperty(exports, "SigningGroupNotInitializedError", { enumerable: true, get: function () { return signing_group_1.SigningGroupNotInitializedError; } }); | ||
var api_client_1 = require("./api-client"); | ||
Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } }); |
@@ -5,2 +5,4 @@ "use strict"; | ||
const signing_group_1 = require("../signing-group"); | ||
const api_client_1 = require("../api-client"); | ||
const resolveApiUrl_1 = require("./resolveApiUrl"); | ||
const { Router } = require("lambda-router"); | ||
@@ -19,3 +21,3 @@ function createWalletLambdaHandler(walletImplementation, prefix) { | ||
router.get(CLIENT_PREFIX + "/address/{groupId}", async (event, context) => { | ||
const signer = new signing_group_1.SigningGroup(event.pathParameters.groupId); | ||
const signer = new signing_group_1.SigningGroup(event.pathParameters.groupId, context.api); | ||
const wallet = new walletImplementation(signer); | ||
@@ -28,3 +30,3 @@ return { | ||
router.get(CLIENT_PREFIX + "/balance/{groupId}", async (event, context) => { | ||
const signer = new signing_group_1.SigningGroup(event.pathParameters.groupId); | ||
const signer = new signing_group_1.SigningGroup(event.pathParameters.groupId, context.api); | ||
const wallet = new walletImplementation(signer); | ||
@@ -37,3 +39,3 @@ return { | ||
router.get(CLIENT_PREFIX + "/transactions/{groupId}", async (event, context) => { | ||
const signer = new signing_group_1.SigningGroup(event.pathParameters.groupId); | ||
const signer = new signing_group_1.SigningGroup(event.pathParameters.groupId, context.api); | ||
const wallet = new walletImplementation(signer); | ||
@@ -46,3 +48,3 @@ return { | ||
router.post(CLIENT_PREFIX + "/transactions/{groupId}", async (event, context) => { | ||
const signer = new signing_group_1.SigningGroup(event.pathParameters.groupId); | ||
const signer = new signing_group_1.SigningGroup(event.pathParameters.groupId, context.api); | ||
const wallet = new walletImplementation(signer); | ||
@@ -73,2 +75,7 @@ console.log("EVENT: ", event); | ||
// }); | ||
const api = new api_client_1.ApiClient({ | ||
baseUrl: resolveApiUrl_1.resolveApiUrl(), | ||
headers: { authorization: lambdaEvent.headers.authorization }, | ||
}); | ||
context.api = context; | ||
let result = await router.route(lambdaEvent, context); | ||
@@ -75,0 +82,0 @@ return result.response; |
@@ -1,2 +0,2 @@ | ||
export { SigningGroup, createSigningGroup } from './SigningGroup'; | ||
export { SigningGroupNotInitializedError } from './SigningGroupNotInitializedError'; | ||
export { SigningGroup } from "./SigningGroup"; | ||
export { SigningGroupNotInitializedError } from "./SigningGroupNotInitializedError"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SigningGroupNotInitializedError = exports.createSigningGroup = exports.SigningGroup = void 0; | ||
exports.SigningGroupNotInitializedError = exports.SigningGroup = void 0; | ||
var SigningGroup_1 = require("./SigningGroup"); | ||
Object.defineProperty(exports, "SigningGroup", { enumerable: true, get: function () { return SigningGroup_1.SigningGroup; } }); | ||
Object.defineProperty(exports, "createSigningGroup", { enumerable: true, get: function () { return SigningGroup_1.createSigningGroup; } }); | ||
var SigningGroupNotInitializedError_1 = require("./SigningGroupNotInitializedError"); | ||
Object.defineProperty(exports, "SigningGroupNotInitializedError", { enumerable: true, get: function () { return SigningGroupNotInitializedError_1.SigningGroupNotInitializedError; } }); |
/// <reference types="node" /> | ||
export declare class SigningGroup { | ||
#private; | ||
static create(groupId: string): Promise<SigningGroup>; | ||
private groupId; | ||
constructor(groupId: string); | ||
init(): Promise<void>; | ||
getPublicKey(): Buffer; | ||
getPublicKeyAsHex(): Buffer; | ||
getPublicKeyAsync(asHex: boolean): Promise<Buffer>; | ||
getPublicKey(asHex?: boolean): Promise<Buffer>; | ||
sign(hash: Buffer): Promise<any>; | ||
} | ||
export declare function createSigningGroup(t: number, n: number): Promise<string>; |
"use strict"; | ||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to set private field on non-instance"); | ||
} | ||
privateMap.set(receiver, value); | ||
return value; | ||
}; | ||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to get private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _groupId, _publicKey, _publicKeyAsHex, _isInitialized; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSigningGroup = exports.SigningGroup = void 0; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const SigningGroupNotInitializedError_1 = require("./SigningGroupNotInitializedError"); | ||
const DEFAULT_SIGNING_GROUP_API_URL = 'http://api.xkey.ninja:8000/'; | ||
let API_URL = process.env.SIGNING_API_URL; | ||
if (!API_URL) { | ||
console.warn(`SigningGroup: SIGNING_API_URL is not initialized, using default: ${DEFAULT_SIGNING_GROUP_API_URL}`); | ||
API_URL = DEFAULT_SIGNING_GROUP_API_URL; | ||
} | ||
const API_URL = process.env.SIGNING_API_URL || "http://api.xkey.ninja:8000/"; | ||
class SigningGroup { | ||
constructor(groupId) { | ||
_groupId.set(this, void 0); | ||
_publicKey.set(this, void 0); | ||
_publicKeyAsHex.set(this, void 0); | ||
_isInitialized.set(this, void 0); | ||
__classPrivateFieldSet(this, _groupId, groupId); | ||
__classPrivateFieldSet(this, _isInitialized, false); | ||
this.groupId = groupId; | ||
} | ||
static async create(groupId) { | ||
const signingGroup = new SigningGroup(groupId); | ||
await signingGroup.init(); | ||
return signingGroup; | ||
} | ||
async init() { | ||
__classPrivateFieldSet(this, _publicKeyAsHex, await this.getPublicKeyAsync(true)); | ||
__classPrivateFieldSet(this, _publicKey, await this.getPublicKeyAsync(false)); | ||
__classPrivateFieldSet(this, _isInitialized, true); | ||
} | ||
getPublicKey() { | ||
if (!__classPrivateFieldGet(this, _isInitialized)) { | ||
throw new SigningGroupNotInitializedError_1.SigningGroupNotInitializedError(); | ||
} | ||
return __classPrivateFieldGet(this, _publicKey); | ||
} | ||
getPublicKeyAsHex() { | ||
if (!__classPrivateFieldGet(this, _isInitialized)) { | ||
throw new SigningGroupNotInitializedError_1.SigningGroupNotInitializedError(); | ||
} | ||
return __classPrivateFieldGet(this, _publicKeyAsHex); | ||
} | ||
async getPublicKeyAsync(asHex) { | ||
const res = await node_fetch_1.default(`${API_URL}/groups/${__classPrivateFieldGet(this, _groupId)}/config`, { | ||
async getPublicKey(asHex = true) { | ||
const res = await node_fetch_1.default(`${API_URL}/groups/${this.groupId}/config`, { | ||
headers: { | ||
Accept: 'application/json', | ||
Accept: "application/json", | ||
}, | ||
@@ -68,3 +21,3 @@ }); | ||
if (asHex) { | ||
return Buffer.from(key, 'hex'); | ||
return Buffer.from(key, "hex"); | ||
} | ||
@@ -76,9 +29,9 @@ else { | ||
async sign(hash) { | ||
const message = hash.toString('hex'); | ||
const res = await node_fetch_1.default(`${API_URL}/sign/${__classPrivateFieldGet(this, _groupId)}`, { | ||
method: 'POST', | ||
const message = hash.toString("hex"); | ||
const res = await node_fetch_1.default(`${API_URL}/sign/${this.groupId}`, { | ||
method: "POST", | ||
body: JSON.stringify({ message }), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
}, | ||
@@ -90,10 +43,9 @@ }); | ||
exports.SigningGroup = SigningGroup; | ||
_groupId = new WeakMap(), _publicKey = new WeakMap(), _publicKeyAsHex = new WeakMap(), _isInitialized = new WeakMap(); | ||
async function createSigningGroup(t, n) { | ||
const res = await node_fetch_1.default(`${API_URL}/start`, { | ||
method: 'POST', | ||
body: JSON.stringify({ parties: '' + n, threshold: '' + t }), | ||
method: "POST", | ||
body: JSON.stringify({ parties: "" + n, threshold: "" + t }), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
}, | ||
@@ -106,6 +58,6 @@ }); | ||
while (!key) { | ||
console.info('[int-kit] Sleeping...'); | ||
console.log("[int-kit] Sleeping..."); | ||
await sleep(2000); | ||
key = await signer.getPublicKeyAsync(false); | ||
console.info('[int-kit] KEY: ', key); | ||
key = await signer.getPublicKey(false); | ||
console.log("[int-kit] KEY: ", key); | ||
} | ||
@@ -115,6 +67,4 @@ return group_id; | ||
exports.createSigningGroup = createSigningGroup; | ||
const sleep = (ms) => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
}; | ||
function sleep(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} |
/// <reference types="node" /> | ||
import { ApiClient } from "../api-client"; | ||
export declare class SigningGroup { | ||
#private; | ||
static create(groupId: string): Promise<SigningGroup>; | ||
constructor(groupId: string); | ||
static create(groupId: string, api: ApiClient): Promise<SigningGroup>; | ||
constructor(groupId: string, api: ApiClient); | ||
init(): Promise<void>; | ||
@@ -12,2 +13,1 @@ getPublicKey(): Buffer; | ||
} | ||
export declare function createSigningGroup(t: number, n: number): Promise<string>; |
@@ -15,18 +15,8 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _groupId, _publicKey, _publicKeyAsHex, _isInitialized; | ||
var _groupId, _publicKey, _publicKeyAsHex, _isInitialized, _api; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSigningGroup = exports.SigningGroup = void 0; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
exports.SigningGroup = void 0; | ||
const SigningGroupNotInitializedError_1 = require("./SigningGroupNotInitializedError"); | ||
const DEFAULT_SIGNING_GROUP_API_URL = 'http://api.xkey.ninja:8000/'; | ||
let API_URL = process.env.SIGNING_API_URL; | ||
if (!API_URL) { | ||
console.warn(`SigningGroup: SIGNING_API_URL is not initialized, using default: ${DEFAULT_SIGNING_GROUP_API_URL}`); | ||
API_URL = DEFAULT_SIGNING_GROUP_API_URL; | ||
} | ||
class SigningGroup { | ||
constructor(groupId) { | ||
constructor(groupId, api) { | ||
_groupId.set(this, void 0); | ||
@@ -36,7 +26,9 @@ _publicKey.set(this, void 0); | ||
_isInitialized.set(this, void 0); | ||
_api.set(this, void 0); | ||
__classPrivateFieldSet(this, _groupId, groupId); | ||
__classPrivateFieldSet(this, _isInitialized, false); | ||
__classPrivateFieldSet(this, _api, api); | ||
} | ||
static async create(groupId) { | ||
const signingGroup = new SigningGroup(groupId); | ||
static async create(groupId, api) { | ||
const signingGroup = new SigningGroup(groupId, api); | ||
await signingGroup.init(); | ||
@@ -63,10 +55,5 @@ return signingGroup; | ||
async getPublicKeyAsync(asHex) { | ||
const res = await node_fetch_1.default(`${API_URL}/groups/${__classPrivateFieldGet(this, _groupId)}/config`, { | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
}); | ||
const { key } = await res.json(); | ||
const { data: { key }, } = await __classPrivateFieldGet(this, _api).get(`groups/${__classPrivateFieldGet(this, _groupId)}/config`); | ||
if (asHex) { | ||
return Buffer.from(key, 'hex'); | ||
return Buffer.from(key, "hex"); | ||
} | ||
@@ -78,42 +65,10 @@ else { | ||
async sign(hash) { | ||
const message = hash.toString('hex'); | ||
const res = await node_fetch_1.default(`${API_URL}/sign/${__classPrivateFieldGet(this, _groupId)}`, { | ||
method: 'POST', | ||
body: JSON.stringify({ message }), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
}, | ||
const message = hash.toString("hex"); | ||
const { data } = await __classPrivateFieldGet(this, _api).post(`sign/${__classPrivateFieldGet(this, _groupId)}`, { | ||
body: { message }, | ||
}); | ||
return res.json(); | ||
return data; | ||
} | ||
} | ||
exports.SigningGroup = SigningGroup; | ||
_groupId = new WeakMap(), _publicKey = new WeakMap(), _publicKeyAsHex = new WeakMap(), _isInitialized = new WeakMap(); | ||
async function createSigningGroup(t, n) { | ||
const res = await node_fetch_1.default(`${API_URL}/start`, { | ||
method: 'POST', | ||
body: JSON.stringify({ parties: '' + n, threshold: '' + t }), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
}, | ||
}); | ||
const { group_id } = await res.json(); | ||
// WORKAROUND: waiting for group to be in sync | ||
let key; | ||
const signer = new SigningGroup(group_id); | ||
while (!key) { | ||
console.info('[int-kit] Sleeping...'); | ||
await sleep(2000); | ||
key = await signer.getPublicKeyAsync(false); | ||
console.info('[int-kit] KEY: ', key); | ||
} | ||
return group_id; | ||
} | ||
exports.createSigningGroup = createSigningGroup; | ||
const sleep = (ms) => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
}; | ||
_groupId = new WeakMap(), _publicKey = new WeakMap(), _publicKeyAsHex = new WeakMap(), _isInitialized = new WeakMap(), _api = new WeakMap(); |
{ | ||
"name": "@dfns/blockchain-integration", | ||
"version": "2.1.1", | ||
"description": "Blockchain integration Kit for DFNS", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"node_modules/**/*", | ||
"lib/**/*" | ||
], | ||
"scripts": { | ||
"clean": "rimraf ./dist", | ||
"build": "tsc", | ||
"test": "jest spec", | ||
"cleanBuild": "npm run clean && npm run build" | ||
}, | ||
"author": "", | ||
"license": "SEE LICENSE IN XKEY_LICENSE", | ||
"dependencies": { | ||
"lambda-router": "^2.10.0", | ||
"node-fetch": "^2.6.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node-fetch": "^2.5.10", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.4" | ||
} | ||
"name": "@dfns/blockchain-integration", | ||
"version": "2.2.1", | ||
"description": "Blockchain integration Kit for DFNS", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"node_modules/**/*", | ||
"lib/**/*" | ||
], | ||
"scripts": { | ||
"clean": "rimraf ./dist", | ||
"build": "tsc", | ||
"test": "jest spec", | ||
"cleanBuild": "npm run clean && npm run build" | ||
}, | ||
"author": "", | ||
"license": "SEE LICENSE IN XKEY_LICENSE", | ||
"dependencies": { | ||
"jsonwebtoken": "^8.5.1", | ||
"lambda-router": "^2.10.0", | ||
"lodash": "^4.17.21", | ||
"node-fetch": "^2.6.1" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash": "^4.14.170", | ||
"@types/node-fetch": "^2.5.10", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.4" | ||
} | ||
} |
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
Network access
Supply chain riskThis module accesses the network.
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
21278
32
519
2
4
5
1
+ Addedjsonwebtoken@^8.5.1
+ Addedlodash@^4.17.21
+ Addedbuffer-equal-constant-time@1.0.1(transitive)
+ Addedecdsa-sig-formatter@1.0.11(transitive)
+ Addedjsonwebtoken@8.5.1(transitive)
+ Addedjwa@1.4.1(transitive)
+ Addedjws@3.2.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.includes@4.3.0(transitive)
+ Addedlodash.isboolean@3.0.3(transitive)
+ Addedlodash.isinteger@4.0.4(transitive)
+ Addedlodash.isnumber@3.0.3(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.isstring@4.0.1(transitive)
+ Addedlodash.once@4.1.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsemver@5.7.2(transitive)