-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ede9ab4
commit dd9ad3c
Showing
12 changed files
with
253 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
if (typeof __dirname === 'undefined') global.__dirname = '/' | ||
if (typeof __filename === 'undefined') global.__filename = '' | ||
if (typeof process === 'undefined') { | ||
global.process = require('process') | ||
} else { | ||
const bProcess = require('process') | ||
for (var p in bProcess) { | ||
if (!(p in process)) { | ||
process[p] = bProcess[p] | ||
} | ||
} | ||
} | ||
|
||
process.browser = false | ||
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer | ||
|
||
// global.location = global.location || { port: 80 } | ||
const isDev = typeof __DEV__ === 'boolean' && __DEV__ | ||
process.env['NODE_ENV'] = isDev ? 'development' : 'production' | ||
if (typeof localStorage !== 'undefined') { | ||
localStorage.debug = isDev ? '*' : '' | ||
} | ||
|
||
// If using the crypto shim, uncomment the following line to ensure | ||
// crypto is loaded first, so it can populate global.crypto | ||
// require('crypto') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ const PageHome = ({navigation}) => { | |
dispatch(setData(data)); | ||
}} | ||
/> | ||
|
||
</View> | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// import crypto from 'crypto'; | ||
|
||
import Config from '../../utils/config'; | ||
import CurveParam from '../../crypto/curveParam'; | ||
import types from "../../utils/types"; | ||
import mimc from "../../crypto/mimc"; | ||
|
||
|
||
export default class CoinCommitment { | ||
constructor( | ||
cm_own = undefined, | ||
cm_del = undefined | ||
) { | ||
this.cm_own = cm_own | ||
this.cm_del = cm_del | ||
} | ||
|
||
static makeCm({ | ||
pk_own_peer, | ||
pk_own_del, | ||
pk_enc_cons, | ||
r_cm, | ||
fee_own, | ||
fee_del, | ||
h_k | ||
}) { | ||
const mimc7 = new mimc.MiMC7(); | ||
|
||
const cm_own = mimc7.hash(pk_own_peer, r_cm, fee_own, h_k, pk_enc_cons); | ||
const cm_del = mimc7.hash(pk_own_del, r_cm, fee_del, h_k, pk_enc_cons); | ||
|
||
return new CoinCommitment(cm_own, cm_del); | ||
} | ||
|
||
static genCm({ | ||
pk_own_peer, | ||
pk_own_del, | ||
pk_enc_cons, | ||
fee_own, | ||
fee_del, | ||
h_k, | ||
}) { | ||
let prime = CurveParam(Config.EC_TYPE).prime | ||
let bitLength = parseInt(prime.toString(2).length); | ||
// let randomHex = '0x' + crypto.randomBytes(bitLength).toString('hex'); | ||
let randomHex = '0x1122ffffffff' | ||
return this.makeCm({ | ||
pk_own_peer : pk_own_peer, | ||
pk_own_del : pk_own_del, | ||
pk_enc_cons : pk_enc_cons, | ||
r_cm : randomHex, | ||
fee_own : fee_own, | ||
fee_del : fee_del, | ||
h_k : h_k, | ||
}) | ||
} | ||
|
||
toJson(){ | ||
return JSON.stringify(this, null, 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import _ from 'lodash' | ||
import CoinCommitment from "./cm" | ||
|
||
const fee_ratio = 0.3 | ||
|
||
export default class Order { | ||
|
||
pk_enc_cons = undefined | ||
pk_own_cons = undefined | ||
r_cm = undefined | ||
fee_del = undefined | ||
fee_own = undefined | ||
h_k = undefined | ||
|
||
constructor( | ||
pk_enc_cons = undefined, | ||
pk_own_cons = undefined, | ||
r_cm = undefined, | ||
fee_del = undefined, | ||
fee_own = undefined, | ||
h_k = undefined | ||
){ | ||
this.pk_own_cons = pk_own_cons | ||
this.pk_enc_cons = pk_enc_cons | ||
this.r_cm = r_cm | ||
this.fee_del = fee_del | ||
this.fee_own = fee_own | ||
this.h_k = h_k | ||
} | ||
|
||
toJson(){ | ||
return JSON.stringify(this, null, 2); | ||
} | ||
|
||
|
||
makeCoinCommitment(pk_own_peer, pk_own_del) { | ||
const cmInfo = _.merge( | ||
JSON.parse(this.toJson()), | ||
{ | ||
'pk_own_peer' : pk_own_peer, | ||
'pk_own_del' : pk_own_del | ||
} | ||
) | ||
console.log(cmInfo); | ||
return CoinCommitment.makeCm(cmInfo) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
export default class PublicKey{ | ||
type = undefined | ||
pk_enc = undefined | ||
pk_own = undefined | ||
|
||
constructor(pk_own='', pk_enc='', type=''){ | ||
this.type = type | ||
this.pk_enc = pk_enc | ||
this.pk_own = pk_own | ||
} | ||
|
||
toJson() { | ||
const pk_own_type = `pk_own_${this.type}` | ||
const pk_enc_type = `pk_enc_${this.type}` | ||
let pk = {} | ||
pk[pk_own_type] = this.pk_own | ||
pk[pk_enc_type] = this.pk_enc | ||
|
||
return JSON.stringify(pk, null, 2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import _ from 'lodash' | ||
|
||
import Libsnark from "./bridge/libsnark" | ||
import Order from "./struct/order" | ||
import SnarkInput from "./struct/snarkInput"; | ||
|
||
const testSnark = async () => { | ||
let snarkClass = new Libsnark(); | ||
|
||
await snarkClass.init(); | ||
|
||
await snarkClass.readVerifyKeyFromFile('/crs/'); | ||
await snarkClass.readProofKeyFromFile('/crs/'); | ||
|
||
const sampleInput = { | ||
"g_r" : "137", | ||
"c1" : "123", | ||
"cm_own" : "123", | ||
"cm_del" : "123", | ||
"ENA" : ["123", "233"], | ||
"ENA_" :["112", "233"], | ||
"fee_del" : "321", | ||
"fee_own" : "123", | ||
"CT_cons" : ["12","22","32","42","52","62"], | ||
"CT_r" : "123" | ||
} | ||
|
||
const proof = await snarkClass.runProof(sampleInput); | ||
console.log(proof); | ||
|
||
const vf = await snarkClass.runVerify(proof, sampleInput); | ||
console.log('vf:', vf); | ||
|
||
} | ||
|
||
export const testOrder = () => { | ||
|
||
console.log("hi" , Number.parseInt(100 * 0.3)) | ||
|
||
const ord = new Order( | ||
1, | ||
1, | ||
1, | ||
1, | ||
1, | ||
1 | ||
) | ||
console.log(ord.toJson()); | ||
const cm = ord.makeCoinCommitment(1, 1); | ||
console.log(cm.toJson()); | ||
|
||
const snarkInputs = new SnarkInput(); | ||
snarkInputs.uploadOrder(ord); | ||
|
||
console.log(snarkInputs.toJson()) | ||
} | ||
|
||
export default testSnark; |