mirror of
https://github.com/status-im/ens-usernames.git
synced 2025-02-14 11:26:35 +00:00
add initial elliptic curve points generation
This commit is contained in:
parent
5f1c5f7336
commit
e6428cc331
@ -22,6 +22,7 @@
|
|||||||
"@material-ui/icons": "^1.1.0",
|
"@material-ui/icons": "^1.1.0",
|
||||||
"bignumber.js": "^5.0.0",
|
"bignumber.js": "^5.0.0",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
|
"elliptic": "^6.4.1",
|
||||||
"eth-ens-namehash": "^2.0.8",
|
"eth-ens-namehash": "^2.0.8",
|
||||||
"formik": "^0.11.11",
|
"formik": "^0.11.11",
|
||||||
"install": "^0.11.0",
|
"install": "^0.11.0",
|
||||||
|
@ -166,12 +166,13 @@ contract('ENSSubdomainRegistry', function () {
|
|||||||
let subdomain = 'bob2';
|
let subdomain = 'bob2';
|
||||||
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
|
let usernameHash = namehash.hash(subdomain + '.' + domains.free.name);
|
||||||
let contactCode = '0x04dbb31252d9bddb4e4d362c7b9c80cba74732280737af97971f42ccbdc716f3f3efb1db366880e52d09b1bfd59842e833f3004088892b7d14b9ce9e957cea9a82';
|
let contactCode = '0x04dbb31252d9bddb4e4d362c7b9c80cba74732280737af97971f42ccbdc716f3f3efb1db366880e52d09b1bfd59842e833f3004088892b7d14b9ce9e957cea9a82';
|
||||||
|
let points = utils.generateXY(contactCode);
|
||||||
let result = await ENSSubdomainRegistry.methods.register(
|
let result = await ENSSubdomainRegistry.methods.register(
|
||||||
web3Utils.sha3(subdomain),
|
web3Utils.sha3(subdomain),
|
||||||
domains.free.namehash,
|
domains.free.namehash,
|
||||||
registrant,
|
registrant,
|
||||||
utils.zeroBytes32,
|
points.x,
|
||||||
utils.zeroBytes32,
|
points.y,
|
||||||
contactCode
|
contactCode
|
||||||
).send({from: registrant});
|
).send({from: registrant});
|
||||||
|
|
||||||
@ -182,8 +183,8 @@ contract('ENSSubdomainRegistry', function () {
|
|||||||
result = await PublicResolver.methods.text(usernameHash, "statusAccount").call()
|
result = await PublicResolver.methods.text(usernameHash, "statusAccount").call()
|
||||||
assert.equal(result, contactCode, "Resolved contact code not set");
|
assert.equal(result, contactCode, "Resolved contact code not set");
|
||||||
result = await PublicResolver.methods.pubkey(usernameHash).call()
|
result = await PublicResolver.methods.pubkey(usernameHash).call()
|
||||||
assert.equal(result[0], utils.zeroBytes32, "Unexpected resolved pubkey[0]");
|
let pubKey = utils.keyFromXY(result[0], result[1]);
|
||||||
assert.equal(result[1], utils.zeroBytes32, "Unexpected resolved pubkey[1]");
|
assert.equal(pubKey, contactCode, "pubKey does not match contract code");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
var EC = require('elliptic').ec;
|
||||||
|
var ec = new EC('secp256k1');
|
||||||
|
|
||||||
// This has been tested with the real Ethereum network and Testrpc.
|
// This has been tested with the real Ethereum network and Testrpc.
|
||||||
// Copied and edited from: https://gist.github.com/xavierlepretre/d5583222fde52ddfbc58b7cfa0d2d0a9
|
// Copied and edited from: https://gist.github.com/xavierlepretre/d5583222fde52ddfbc58b7cfa0d2d0a9
|
||||||
@ -237,3 +239,19 @@ exports.increaseTime = async (amount) => {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.generateXY = pub => {
|
||||||
|
const stripped = pub.slice(2);
|
||||||
|
const key = ec.keyFromPublic(stripped, 'hex');
|
||||||
|
const pubPoint = key.getPublic();
|
||||||
|
const x = '0x' + pubPoint.getX().toString(16);
|
||||||
|
const y = '0x'+ pubPoint.getY().toString(16);
|
||||||
|
return { x, y };
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.keyFromXY = (X, Y) => {
|
||||||
|
const x = Buffer.from(X.substring(2), 'hex');
|
||||||
|
const y = Buffer.from(Y.substring(2), 'hex');
|
||||||
|
const keys = ec.keyFromPublic({ x, y }, 'hex');
|
||||||
|
return `0x${keys.getPublic().encode('hex')}`;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user