qaci-domainobjs
Advanced tools
Comparing version 1.0.8 to 1.1.0
@@ -1,2 +0,2 @@ | ||
import { EcdhSharedKey, Signature, PubKey as RawPubKey, PrivKey as RawPrivKey, G1Point, G2Point } from 'maci-crypto'; | ||
import { EcdhSharedKey, Signature, PubKey as RawPubKey, PrivKey as RawPrivKey, G1Point, G2Point } from 'qaci-crypto'; | ||
declare class VerifyingKey { | ||
@@ -3,0 +3,0 @@ alpha1: G1Point; |
@@ -15,3 +15,3 @@ "use strict"; | ||
var base64url_1 = require("base64url"); | ||
var maci_crypto_1 = require("maci-crypto"); | ||
var qaci_crypto_1 = require("qaci-crypto"); | ||
var SERIALIZED_PRIV_KEY_PREFIX = 'macisk.'; | ||
@@ -37,3 +37,3 @@ var VerifyingKey = /** @class */ (function () { | ||
var convertG2 = function (point) { | ||
return new maci_crypto_1.G2Point([ | ||
return new qaci_crypto_1.G2Point([ | ||
BigInt(point.x[0]), | ||
@@ -46,3 +46,3 @@ BigInt(point.x[1]), | ||
}; | ||
return new VerifyingKey(new maci_crypto_1.G1Point(BigInt(data.alpha1.x), BigInt(data.alpha1.y)), convertG2(data.beta2), convertG2(data.gamma2), convertG2(data.delta2), data.ic.map(function (c) { return new maci_crypto_1.G1Point(BigInt(c.x), BigInt(c.y)); })); | ||
return new VerifyingKey(new qaci_crypto_1.G1Point(BigInt(data.alpha1.x), BigInt(data.alpha1.y)), convertG2(data.beta2), convertG2(data.gamma2), convertG2(data.delta2), data.ic.map(function (c) { return new qaci_crypto_1.G1Point(BigInt(c.x), BigInt(c.y)); })); | ||
}; | ||
@@ -67,3 +67,3 @@ VerifyingKey.prototype.equals = function (vk) { | ||
var copyG2 = function (point) { | ||
return new maci_crypto_1.G2Point([ | ||
return new qaci_crypto_1.G2Point([ | ||
BigInt(point.x[0].toString()), | ||
@@ -76,3 +76,3 @@ BigInt(point.x[1].toString()), | ||
}; | ||
return new VerifyingKey(new maci_crypto_1.G1Point(BigInt(this.alpha1.x.toString()), BigInt(this.alpha1.y.toString())), copyG2(this.beta2), copyG2(this.gamma2), copyG2(this.delta2), this.ic.map(function (c) { return new maci_crypto_1.G1Point(BigInt(c.x.toString()), BigInt(c.y.toString())); })); | ||
return new VerifyingKey(new qaci_crypto_1.G1Point(BigInt(this.alpha1.x.toString()), BigInt(this.alpha1.y.toString())), copyG2(this.beta2), copyG2(this.gamma2), copyG2(this.delta2), this.ic.map(function (c) { return new qaci_crypto_1.G1Point(BigInt(c.x.toString()), BigInt(c.y.toString())); })); | ||
}; | ||
@@ -84,4 +84,4 @@ VerifyingKey.fromJSON = function (j) { | ||
VerifyingKey.fromObj = function (data) { | ||
var alpha1 = new maci_crypto_1.G1Point(BigInt(data.vk_alpha_1[0]), BigInt(data.vk_alpha_1[1])); | ||
var beta2 = new maci_crypto_1.G2Point([ | ||
var alpha1 = new qaci_crypto_1.G1Point(BigInt(data.vk_alpha_1[0]), BigInt(data.vk_alpha_1[1])); | ||
var beta2 = new qaci_crypto_1.G2Point([ | ||
BigInt(data.vk_beta_2[0][1]), | ||
@@ -93,3 +93,3 @@ BigInt(data.vk_beta_2[0][0]), | ||
]); | ||
var gamma2 = new maci_crypto_1.G2Point([ | ||
var gamma2 = new qaci_crypto_1.G2Point([ | ||
BigInt(data.vk_gamma_2[0][1]), | ||
@@ -101,3 +101,3 @@ BigInt(data.vk_gamma_2[0][0]), | ||
]); | ||
var delta2 = new maci_crypto_1.G2Point([ | ||
var delta2 = new qaci_crypto_1.G2Point([ | ||
BigInt(data.vk_delta_2[0][1]), | ||
@@ -109,3 +109,3 @@ BigInt(data.vk_delta_2[0][0]), | ||
]); | ||
var ic = data.IC.map(function (ic) { return new maci_crypto_1.G1Point(BigInt(ic[0]), BigInt(ic[1])); }); | ||
var ic = data.IC.map(function (ic) { return new qaci_crypto_1.G1Point(BigInt(ic[0]), BigInt(ic[1])); }); | ||
return new VerifyingKey(alpha1, beta2, gamma2, delta2, ic); | ||
@@ -123,3 +123,3 @@ }; | ||
this.asCircuitInputs = function () { | ||
return (0, maci_crypto_1.formatPrivKeyForBabyJub)(_this.rawPrivKey).toString(); | ||
return (0, qaci_crypto_1.formatPrivKeyForBabyJub)(_this.rawPrivKey).toString(); | ||
}; | ||
@@ -141,3 +141,3 @@ this.serialize = function () { | ||
var value = BigInt('0x' + x); | ||
validValue = value < maci_crypto_1.SNARK_FIELD_SIZE; | ||
validValue = value < qaci_crypto_1.SNARK_FIELD_SIZE; | ||
} | ||
@@ -183,7 +183,7 @@ catch (_a) { | ||
} | ||
var packed = (0, maci_crypto_1.packPubKey)(_this.rawPubKey).toString('hex'); | ||
var packed = (0, qaci_crypto_1.packPubKey)(_this.rawPubKey).toString('hex'); | ||
return SERIALIZED_PUB_KEY_PREFIX + packed.toString(); | ||
}; | ||
this.hash = function () { | ||
return (0, maci_crypto_1.hashLeftRight)(_this.rawPubKey[0], _this.rawPubKey[1]); | ||
return (0, qaci_crypto_1.hashLeftRight)(_this.rawPubKey[0], _this.rawPubKey[1]); | ||
}; | ||
@@ -195,4 +195,4 @@ this.equals = function (p) { | ||
assert(rawPubKey.length === 2); | ||
assert(rawPubKey[0] < maci_crypto_1.SNARK_FIELD_SIZE); | ||
assert(rawPubKey[1] < maci_crypto_1.SNARK_FIELD_SIZE); | ||
assert(rawPubKey[0] < qaci_crypto_1.SNARK_FIELD_SIZE); | ||
assert(rawPubKey[1] < qaci_crypto_1.SNARK_FIELD_SIZE); | ||
this.rawPubKey = rawPubKey; | ||
@@ -207,3 +207,3 @@ } | ||
var packed = Buffer.from(s.slice(len), 'hex'); | ||
return new PubKey((0, maci_crypto_1.unpackPubKey)(packed)); | ||
return new PubKey((0, qaci_crypto_1.unpackPubKey)(packed)); | ||
}; | ||
@@ -233,6 +233,6 @@ PubKey.isValidSerializedPubKey = function (s) { | ||
this.privKey = privKey; | ||
this.pubKey = new PubKey((0, maci_crypto_1.genPubKey)(privKey.rawPrivKey)); | ||
this.pubKey = new PubKey((0, qaci_crypto_1.genPubKey)(privKey.rawPrivKey)); | ||
} | ||
else { | ||
var rawKeyPair = (0, maci_crypto_1.genKeypair)(); | ||
var rawKeyPair = (0, qaci_crypto_1.genKeypair)(); | ||
this.privKey = new PrivKey(rawKeyPair.privKey); | ||
@@ -243,3 +243,3 @@ this.pubKey = new PubKey(rawKeyPair.pubKey); | ||
Keypair.genEcdhSharedKey = function (privKey, pubKey) { | ||
return (0, maci_crypto_1.genEcdhSharedKey)(privKey.rawPrivKey, pubKey.rawPubKey); | ||
return (0, qaci_crypto_1.genEcdhSharedKey)(privKey.rawPrivKey, pubKey.rawPubKey); | ||
}; | ||
@@ -279,3 +279,3 @@ Keypair.prototype.equals = function (keypair) { | ||
this.hash = function (_encPubKey) { | ||
return (0, maci_crypto_1.hash12)(__spreadArray(__spreadArray([], _this.data, true), _encPubKey.rawPubKey, true)); | ||
return (0, qaci_crypto_1.hash12)(__spreadArray(__spreadArray([], _this.data, true), _encPubKey.rawPubKey, true)); | ||
}; | ||
@@ -317,3 +317,3 @@ this.copy = function () { | ||
var vals = _this.asArray(); | ||
return (0, maci_crypto_1.hashLeftRight)(vals[0], vals[1]); | ||
return (0, qaci_crypto_1.hashLeftRight)(vals[0], vals[1]); | ||
}; | ||
@@ -331,3 +331,3 @@ this.asCircuitInputs = function () { | ||
} | ||
var voTree = new maci_crypto_1.IncrementalQuinTree(_this.voteOptionTreeDepth, BigInt(0), 5, maci_crypto_1.hash5); | ||
var voTree = new qaci_crypto_1.IncrementalQuinTree(_this.voteOptionTreeDepth, BigInt(0), 5, qaci_crypto_1.hash5); | ||
for (var i = 0; i <= lastIndexToInsert; i++) { | ||
@@ -362,3 +362,3 @@ voTree.insert(_this.votes[i]); | ||
var ballot = new Ballot(_numVoteOptions, _voteOptionTreeDepth); | ||
ballot.nonce = (0, maci_crypto_1.genRandomSalt)(); | ||
ballot.nonce = (0, qaci_crypto_1.genRandomSalt)(); | ||
return ballot; | ||
@@ -389,3 +389,3 @@ }; | ||
this.hash = function () { | ||
return (0, maci_crypto_1.hash4)(_this.asArray()); | ||
return (0, qaci_crypto_1.hash4)(_this.asArray()); | ||
}; | ||
@@ -426,3 +426,3 @@ this.serialize = function () { | ||
var keypair = new Keypair(); | ||
return new StateLeaf(keypair.pubKey, (0, maci_crypto_1.genRandomSalt)(), BigInt(0)); | ||
return new StateLeaf(keypair.pubKey, (0, qaci_crypto_1.genRandomSalt)(), BigInt(0)); | ||
}; | ||
@@ -453,3 +453,3 @@ StateLeaf.prototype.asContractParam = function () { | ||
function Command(stateIndex, newPubKey, voteOptionIndex, newVoteWeight, nonce, pollId, salt) { | ||
if (salt === void 0) { salt = (0, maci_crypto_1.genRandomSalt)(); } | ||
if (salt === void 0) { salt = (0, qaci_crypto_1.genRandomSalt)(); } | ||
var _this = this; | ||
@@ -495,3 +495,3 @@ this.copy = function () { | ||
this.hash = function () { | ||
return (0, maci_crypto_1.hash4)(_this.asArray()); | ||
return (0, qaci_crypto_1.hash4)(_this.asArray()); | ||
}; | ||
@@ -502,3 +502,3 @@ /* | ||
this.sign = function (privKey) { | ||
return (0, maci_crypto_1.sign)(privKey.rawPrivKey, _this.hash()); | ||
return (0, qaci_crypto_1.sign)(privKey.rawPrivKey, _this.hash()); | ||
}; | ||
@@ -511,3 +511,3 @@ /* | ||
this.verifySignature = function (signature, pubKey) { | ||
return (0, maci_crypto_1.verifySignature)(_this.hash(), signature, pubKey.rawPubKey); | ||
return (0, qaci_crypto_1.verifySignature)(_this.hash(), signature, pubKey.rawPubKey); | ||
}; | ||
@@ -531,3 +531,3 @@ /* | ||
assert(plaintext.length === 7); | ||
var ciphertext = (0, maci_crypto_1.encrypt)(plaintext, sharedKey, BigInt(0)); | ||
var ciphertext = (0, qaci_crypto_1.encrypt)(plaintext, sharedKey, BigInt(0)); | ||
var message = new Message(ciphertext); | ||
@@ -554,3 +554,3 @@ return message; | ||
Command.decrypt = function (message, sharedKey) { | ||
var decrypted = (0, maci_crypto_1.decrypt)(message.data, sharedKey, BigInt(0), 7); | ||
var decrypted = (0, qaci_crypto_1.decrypt)(message.data, sharedKey, BigInt(0), 7); | ||
var p = BigInt("".concat(decrypted[0])); | ||
@@ -557,0 +557,0 @@ // Returns the value of the 50 bits at position `pos` in `val` |
{ | ||
"name": "qaci-domainobjs", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -16,3 +16,3 @@ "main": "build/index.js", | ||
"jest": "^26.6.3", | ||
"qaci-crypto": "^1.0.8", | ||
"qaci-crypto": "^1.1.0", | ||
"ts-jest": "^26.5.4" | ||
@@ -23,3 +23,3 @@ }, | ||
}, | ||
"gitHead": "062a830aae8e5d6ec66028dd2dc5d3a33fe7e9d9" | ||
"gitHead": "7323760d96e7cdbc8c2effc70cb038254dba40c8" | ||
} |