@keystonehq/bc-ur-registry-eth
Advanced tools
Comparing version 0.3.2 to 0.3.4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ETHSignature = void 0; | ||
const bc_ur_registry_1 = require("@keystonehq/bc-ur-registry"); | ||
const RegistryType_1 = require("./RegistryType"); | ||
const { RegistryItem, RegistryTypes, decodeToDataItem } = bc_ur_registry_1.extend; | ||
var tslib_1 = require("tslib"); | ||
var bc_ur_registry_1 = require("@keystonehq/bc-ur-registry"); | ||
var RegistryType_1 = require("./RegistryType"); | ||
var RegistryItem = bc_ur_registry_1.extend.RegistryItem, RegistryTypes = bc_ur_registry_1.extend.RegistryTypes, decodeToDataItem = bc_ur_registry_1.extend.decodeToDataItem; | ||
var Keys; | ||
@@ -12,31 +13,34 @@ (function (Keys) { | ||
})(Keys || (Keys = {})); | ||
class ETHSignature extends RegistryItem { | ||
constructor(signature, requestId) { | ||
super(); | ||
this.getRegistryType = () => RegistryType_1.ExtendedRegistryTypes.ETH_SIGNATAURE; | ||
this.getRequestId = () => this.requestId; | ||
this.getSignature = () => this.signature; | ||
this.toDataItem = () => { | ||
const map = {}; | ||
if (this.requestId) { | ||
map[Keys.requestId] = new bc_ur_registry_1.DataItem(this.requestId, RegistryTypes.UUID.getTag()); | ||
var ETHSignature = (function (_super) { | ||
tslib_1.__extends(ETHSignature, _super); | ||
function ETHSignature(signature, requestId) { | ||
var _this = _super.call(this) || this; | ||
_this.getRegistryType = function () { return RegistryType_1.ExtendedRegistryTypes.ETH_SIGNATAURE; }; | ||
_this.getRequestId = function () { return _this.requestId; }; | ||
_this.getSignature = function () { return _this.signature; }; | ||
_this.toDataItem = function () { | ||
var map = {}; | ||
if (_this.requestId) { | ||
map[Keys.requestId] = new bc_ur_registry_1.DataItem(_this.requestId, RegistryTypes.UUID.getTag()); | ||
} | ||
map[Keys.signature] = this.signature; | ||
map[Keys.signature] = _this.signature; | ||
return new bc_ur_registry_1.DataItem(map); | ||
}; | ||
this.signature = signature; | ||
this.requestId = requestId; | ||
_this.signature = signature; | ||
_this.requestId = requestId; | ||
return _this; | ||
} | ||
} | ||
ETHSignature.fromDataItem = function (dataItem) { | ||
var map = dataItem.getData(); | ||
var signature = map[Keys.signature]; | ||
var requestId = map[Keys.requestId] ? map[Keys.requestId].getData() : undefined; | ||
return new ETHSignature(signature, requestId); | ||
}; | ||
ETHSignature.fromCBOR = function (_cborPayload) { | ||
var dataItem = decodeToDataItem(_cborPayload); | ||
return ETHSignature.fromDataItem(dataItem); | ||
}; | ||
return ETHSignature; | ||
}(RegistryItem)); | ||
exports.ETHSignature = ETHSignature; | ||
ETHSignature.fromDataItem = (dataItem) => { | ||
const map = dataItem.getData(); | ||
const signature = map[Keys.signature]; | ||
const requestId = map[Keys.requestId] ? map[Keys.requestId].getData() : undefined; | ||
return new ETHSignature(signature, requestId); | ||
}; | ||
ETHSignature.fromCBOR = (_cborPayload) => { | ||
const dataItem = decodeToDataItem(_cborPayload); | ||
return ETHSignature.fromDataItem(dataItem); | ||
}; | ||
//# sourceMappingURL=EthSignature.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EthSignRequest = exports.DataType = void 0; | ||
const tslib_1 = require("tslib"); | ||
const bc_ur_registry_1 = require("@keystonehq/bc-ur-registry"); | ||
const RegistryType_1 = require("./RegistryType"); | ||
const uuid = tslib_1.__importStar(require("uuid")); | ||
const { RegistryItem, decodeToDataItem, RegistryTypes } = bc_ur_registry_1.extend; | ||
var tslib_1 = require("tslib"); | ||
var bc_ur_registry_1 = require("@keystonehq/bc-ur-registry"); | ||
var RegistryType_1 = require("./RegistryType"); | ||
var uuid = tslib_1.__importStar(require("uuid")); | ||
var RegistryItem = bc_ur_registry_1.extend.RegistryItem, decodeToDataItem = bc_ur_registry_1.extend.decodeToDataItem, RegistryTypes = bc_ur_registry_1.extend.RegistryTypes; | ||
var Keys; | ||
@@ -25,83 +25,86 @@ (function (Keys) { | ||
})(DataType = exports.DataType || (exports.DataType = {})); | ||
class EthSignRequest extends RegistryItem { | ||
constructor(args) { | ||
super(); | ||
this.args = args; | ||
this.getRegistryType = () => RegistryType_1.ExtendedRegistryTypes.ETH_SIGN_REQUEST; | ||
this.setupData = (args) => { | ||
this.requestId = args.requestId; | ||
this.signData = args.signData; | ||
this.dataType = args.dataType; | ||
this.chainId = args.chainId; | ||
this.derivationPath = args.derivationPath; | ||
this.address = args.address; | ||
var EthSignRequest = (function (_super) { | ||
tslib_1.__extends(EthSignRequest, _super); | ||
function EthSignRequest(args) { | ||
var _this = _super.call(this) || this; | ||
_this.args = args; | ||
_this.getRegistryType = function () { return RegistryType_1.ExtendedRegistryTypes.ETH_SIGN_REQUEST; }; | ||
_this.setupData = function (args) { | ||
_this.requestId = args.requestId; | ||
_this.signData = args.signData; | ||
_this.dataType = args.dataType; | ||
_this.chainId = args.chainId; | ||
_this.derivationPath = args.derivationPath; | ||
_this.address = args.address; | ||
}; | ||
this.getRequestId = () => this.requestId; | ||
this.getSignData = () => this.signData; | ||
this.getDataType = () => this.dataType; | ||
this.getChainId = () => this.chainId; | ||
this.getDerivationPath = () => this.derivationPath.getPath(); | ||
this.getSignRequestAddress = () => this.address; | ||
this.toDataItem = () => { | ||
const map = {}; | ||
if (this.requestId) { | ||
map[Keys.requestId] = new bc_ur_registry_1.DataItem(this.requestId, RegistryTypes.UUID.getTag()); | ||
_this.getRequestId = function () { return _this.requestId; }; | ||
_this.getSignData = function () { return _this.signData; }; | ||
_this.getDataType = function () { return _this.dataType; }; | ||
_this.getChainId = function () { return _this.chainId; }; | ||
_this.getDerivationPath = function () { return _this.derivationPath.getPath(); }; | ||
_this.getSignRequestAddress = function () { return _this.address; }; | ||
_this.toDataItem = function () { | ||
var map = {}; | ||
if (_this.requestId) { | ||
map[Keys.requestId] = new bc_ur_registry_1.DataItem(_this.requestId, RegistryTypes.UUID.getTag()); | ||
} | ||
if (this.address) { | ||
map[Keys.address] = this.address; | ||
if (_this.address) { | ||
map[Keys.address] = _this.address; | ||
} | ||
if (this.chainId) { | ||
map[Keys.chainId] = this.chainId; | ||
if (_this.chainId) { | ||
map[Keys.chainId] = _this.chainId; | ||
} | ||
map[Keys.signData] = this.signData; | ||
map[Keys.dataType] = this.dataType; | ||
const keyPath = this.derivationPath.toDataItem(); | ||
keyPath.setTag(this.derivationPath.getRegistryType().getTag()); | ||
map[Keys.signData] = _this.signData; | ||
map[Keys.dataType] = _this.dataType; | ||
var keyPath = _this.derivationPath.toDataItem(); | ||
keyPath.setTag(_this.derivationPath.getRegistryType().getTag()); | ||
map[Keys.derivationPath] = keyPath; | ||
return new bc_ur_registry_1.DataItem(map); | ||
}; | ||
this.setupData(args); | ||
_this.setupData(args); | ||
return _this; | ||
} | ||
static constructETHRequest(signData, signDataType, hdPath, xfp, uuidString, chainId, address) { | ||
const paths = hdPath.replace(/[m|M]\//, '').split('/'); | ||
const hdpathObject = new bc_ur_registry_1.CryptoKeypath(paths.map((path) => { | ||
const index = parseInt(path.replace("'", '')); | ||
let isHardened = false; | ||
EthSignRequest.constructETHRequest = function (signData, signDataType, hdPath, xfp, uuidString, chainId, address) { | ||
var paths = hdPath.replace(/[m|M]\//, '').split('/'); | ||
var hdpathObject = new bc_ur_registry_1.CryptoKeypath(paths.map(function (path) { | ||
var index = parseInt(path.replace("'", '')); | ||
var isHardened = false; | ||
if (path.endsWith("'")) { | ||
isHardened = true; | ||
} | ||
return new bc_ur_registry_1.PathComponent({ index, hardened: isHardened }); | ||
return new bc_ur_registry_1.PathComponent({ index: index, hardened: isHardened }); | ||
}), Buffer.from(xfp, 'hex')); | ||
return new EthSignRequest({ | ||
requestId: uuidString ? Buffer.from(uuid.parse(uuidString)) : undefined, | ||
signData, | ||
signData: signData, | ||
dataType: signDataType, | ||
derivationPath: hdpathObject, | ||
chainId, | ||
chainId: chainId, | ||
address: address ? Buffer.from(address.replace('0x', ''), 'hex') : undefined, | ||
}); | ||
} | ||
} | ||
}; | ||
EthSignRequest.fromDataItem = function (dataItem) { | ||
var map = dataItem.getData(); | ||
var signData = map[Keys.signData]; | ||
var dataType = map[Keys.dataType]; | ||
var derivationPath = bc_ur_registry_1.CryptoKeypath.fromDataItem(map[Keys.derivationPath]); | ||
var chainId = map[Keys.chainId] ? map[Keys.chainId] : undefined; | ||
var address = map[Keys.address] ? map[Keys.address] : undefined; | ||
var requestId = map[Keys.requestId] ? map[Keys.requestId].getData() : undefined; | ||
return new EthSignRequest({ | ||
requestId: requestId, | ||
signData: signData, | ||
dataType: dataType, | ||
chainId: chainId, | ||
derivationPath: derivationPath, | ||
address: address, | ||
}); | ||
}; | ||
EthSignRequest.fromCBOR = function (_cborPayload) { | ||
var dataItem = decodeToDataItem(_cborPayload); | ||
return EthSignRequest.fromDataItem(dataItem); | ||
}; | ||
return EthSignRequest; | ||
}(RegistryItem)); | ||
exports.EthSignRequest = EthSignRequest; | ||
EthSignRequest.fromDataItem = (dataItem) => { | ||
const map = dataItem.getData(); | ||
const signData = map[Keys.signData]; | ||
const dataType = map[Keys.dataType]; | ||
const derivationPath = bc_ur_registry_1.CryptoKeypath.fromDataItem(map[Keys.derivationPath]); | ||
const chainId = map[Keys.chainId] ? map[Keys.chainId] : undefined; | ||
const address = map[Keys.address] ? map[Keys.address] : undefined; | ||
const requestId = map[Keys.requestId] ? map[Keys.requestId].getData() : undefined; | ||
return new EthSignRequest({ | ||
requestId, | ||
signData, | ||
dataType, | ||
chainId, | ||
derivationPath, | ||
address, | ||
}); | ||
}; | ||
EthSignRequest.fromCBOR = (_cborPayload) => { | ||
const dataItem = decodeToDataItem(_cborPayload); | ||
return EthSignRequest.fromDataItem(dataItem); | ||
}; | ||
//# sourceMappingURL=EthSignRequest.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findHDpatfromAddress = exports.generateAddressfromXpub = exports.ETHSignature = exports.DataType = exports.EthSignRequest = void 0; | ||
const tslib_1 = require("tslib"); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("@keystonehq/bc-ur-registry"), exports); | ||
const bc_ur_registry_1 = require("@keystonehq/bc-ur-registry"); | ||
const RegistryType_1 = require("./RegistryType"); | ||
const { cbor } = bc_ur_registry_1.extend; | ||
var bc_ur_registry_1 = require("@keystonehq/bc-ur-registry"); | ||
var RegistryType_1 = require("./RegistryType"); | ||
var cbor = bc_ur_registry_1.extend.cbor; | ||
cbor.patchTags(Object.values(RegistryType_1.ExtendedRegistryTypes) | ||
.filter((rt) => !!rt.getTag()) | ||
.map((rt) => rt.getTag())); | ||
.filter(function (rt) { return !!rt.getTag(); }) | ||
.map(function (rt) { return rt.getTag(); })); | ||
var EthSignRequest_1 = require("./EthSignRequest"); | ||
@@ -13,0 +13,0 @@ Object.defineProperty(exports, "EthSignRequest", { enumerable: true, get: function () { return EthSignRequest_1.EthSignRequest; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ExtendedRegistryTypes = void 0; | ||
const bc_ur_registry_1 = require("@keystonehq/bc-ur-registry"); | ||
const { RegistryType } = bc_ur_registry_1.extend; | ||
var bc_ur_registry_1 = require("@keystonehq/bc-ur-registry"); | ||
var RegistryType = bc_ur_registry_1.extend.RegistryType; | ||
exports.ExtendedRegistryTypes = { | ||
@@ -7,0 +7,0 @@ ETH_SIGN_REQUEST: new RegistryType('eth-sign-request', 401), |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findHDpatfromAddress = exports.generateAddressfromXpub = void 0; | ||
const tslib_1 = require("tslib"); | ||
const hdkey_1 = tslib_1.__importDefault(require("hdkey")); | ||
const ethereumjs_util_1 = require("ethereumjs-util"); | ||
const generateAddressfromXpub = (xpub, derivePath) => { | ||
const node = hdkey_1.default.fromExtendedKey(xpub); | ||
const publicKey = node.derive(derivePath); | ||
const address = '0x' + ethereumjs_util_1.publicToAddress(publicKey.publicKey, true).toString('hex'); | ||
var tslib_1 = require("tslib"); | ||
var hdkey_1 = tslib_1.__importDefault(require("hdkey")); | ||
var ethereumjs_util_1 = require("ethereumjs-util"); | ||
var generateAddressfromXpub = function (xpub, derivePath) { | ||
var node = hdkey_1.default.fromExtendedKey(xpub); | ||
var publicKey = node.derive(derivePath); | ||
var address = '0x' + ethereumjs_util_1.publicToAddress(publicKey.publicKey, true).toString('hex'); | ||
return ethereumjs_util_1.toChecksumAddress(address); | ||
}; | ||
exports.generateAddressfromXpub = generateAddressfromXpub; | ||
const findHDpatfromAddress = (address, xpub, numberLimit, rootPath) => { | ||
for (let i = 0; i < numberLimit; i++) { | ||
let path = `M/0/${i}`; | ||
let caculateAddress = exports.generateAddressfromXpub(xpub, path); | ||
var findHDpatfromAddress = function (address, xpub, numberLimit, rootPath) { | ||
for (var i = 0; i < numberLimit; i++) { | ||
var path = "M/0/" + i; | ||
var caculateAddress = exports.generateAddressfromXpub(xpub, path); | ||
if (address.toLowerCase() == caculateAddress.toLowerCase()) { | ||
return `${rootPath}/0/${i}`; | ||
return rootPath + "/0/" + i; | ||
} | ||
@@ -21,0 +21,0 @@ } |
{ | ||
"name": "@keystonehq/bc-ur-registry-eth", | ||
"version": "0.3.2", | ||
"version": "0.3.4", | ||
"description": "bc-ur-registry extension for ETH", | ||
@@ -38,3 +38,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "d92c8e8087032ba8dab33426a473863c37e1a123" | ||
"gitHead": "a05fe3351532446c62e3f798e4d36ccaae68f204" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
25982
398
1