Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Norton12138 committed Dec 8, 2024
1 parent 5dc3370 commit 943338c
Show file tree
Hide file tree
Showing 258 changed files with 45,780 additions and 1 deletion.
33 changes: 33 additions & 0 deletions 2024-shenzhen-FinTechathon/SpotOn/backend/check/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Homomorphic {
//#p = 67108859;
#p = 67108859n;
Add(ComA, ComB) {
return ComA * ComB % this.#p
}
Pow(Com, n) {
let res = 1n;
let quot = BigInt(n);
let rem = 0n;
let table = [];
table.push(Com);
for(let i = 1; i < 64; i++) {
table.push(table[i - 1] * table[i - 1] % this.#p);
}
for(let j = 0; j < 64; j++) {
rem = quot % 2n;
quot = quot / 2n;
if(rem == 1n) {
res = res * table[j] % this.#p;
} else {}
}
return res
}
Sub(ComA, ComB, ComC) {
if(ComB * ComC % this.#p == ComA) {
return 1
}
else {
return 0
}
}
}

export {Homomorphic};
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* File Name: Pedersen.js
* Project Name: ZeroID
* Author(s): Norton
* Creation Date: 2024-02-01
* Copyright: Copyright (C) 2024 Example Corporation. All rights reserved.
* License: This code is distributed under the MIT license.
* Modification History:
* - 2024-02-02: Initial version by Norton.
* - 2024-02-10: Minor bug fixes by Norton.
* Description: This is an implementation of Pedersen's Commitment in the multiplicative group, written
* in JavaScript language.
* Contact Information: [None]
*/

export class Pedersen {
#g;
#h;
//#p = 67108859;
#p = 67108859n;
#g_table = [];
#h_table = [];
constructor(g, h) {
this.#g = g % this.#p;
this.#h = h % this.#p;
this.#g_table.push(this.#g)
this.#h_table.push(this.#h)
for(let i = 1; i < 64; i++) {
this.#g_table.push(this.#g_table[i - 1] * this.#g_table[i - 1] % this.#p);
this.#h_table.push(this.#h_table[i - 1] * this.#h_table[i - 1] % this.#p);
}
// bebug
// console.log('g:' + this.#g + ' h:' + this.#h)
// console.log('g_table:' + this.#g_table)
// console.log('h_table:' + this.#h_table)
}
Commitment(v, r) {
let v_quot = v;
let r_quot = r;
let v_rem = 0n;
let r_rem = 0n;
let G = 1n;
let H = 1n;
for(let i = 0; i < 64; i++) {
v_rem = v_quot % 2n;
v_quot = v_quot / 2n;
r_rem = r_quot % 2n;
r_quot = r_quot / 2n;
// debug
// console.log(i + ' v_rem:' + v_rem + ' v_qout:' + v_quot);
// console.log(i + ' r_rem:' + r_rem + ' r_qout:' + r_quot);
if(v_rem == 1n) {
G = G * this.#g_table[i] % this.#p;
} else {}
if(r_rem == 1n) {
H = H * this.#h_table[i] % this.#p;
} else {}
}
return G * H % this.#p
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"id": "User",
"time": "2024/11/13 19:09:43",
"proof": {
"emb": [
"0x0000000001af316d",
"0x0000000000bf27bd"
],
"cmt": {
"cmt_eq_old_json": [
"0x00000000002ae14b",
"0x00000000003af9d0"
],
"cmt_eq_new_json": [
"0x0000000003779991",
"0x000000000221d6d4"
],
"cmt_mult_json": [
"0x000000000094f08e",
"0x00000000007b0669"
]
},
"a": [
"0x0000000003609a0d",
"0x0000000002588e16"
],
"z": [
"0x000000003e83836c",
"0x00000000175d9e71",
"0x000000000f45f892",
"0x000000002c63c4ef",
"0x0000000000003e81",
"0x000000000002a2cf",
"0x0000000000538850",
"0x0000000000278921",
"0x000000004a462186",
"0x00000000013e874e",
"0x000000001f9f5997",
"0x000000001f92827b",
"0x00000000000618f6",
"0x0000000000034e9b"
],
"p": [
"0x0000000002e7386b",
"0x00000000003b5d6e",
"0x0000000001ef918f",
"0x0000000001101847",
"0x00000000039507fb",
"0x0000000001d2ae3e"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* File Name: generate.js
* Project Name: ZeroID
* Author(s): Norton
* Creation Date: 2024-02-01
* Copyright: Copyright (C) 2024 Example Corporation. All rights reserved.
* License: This code is distributed under the MIT license.
* Modification History:
* - 2024-02-02: Initial version by Norton.
* - 2024-02-04: Minor bug fixes by Norton.
* Description: This module is used to simulate the process of users generating biometric encoding
* commitments during the registration process.
* Contact Information: [None]
*/

import * as fs from 'fs'
import { Pedersen } from './Pedersen.js'

function InttoHex(Value, length) {
// 转换为十六进制,不包括'0x'前缀
let hex = Value.toString(16);
// 计算需要填充的零的数量
const padding = length - hex.length;
// 如果需要,填充零
if (padding > 0) {
hex = '0x' + '0'.repeat(padding) + hex;
}
else {
hex = '0x' + hex;
}
return hex;
}

// 生物特征编码的维度
const dim = 2
// 承诺的生成元
const g = 56544564n
const h = 237684576n
// 随机生成用的注册生物特征
let m = new Array(dim)
let r = new Array(dim)
for(let i = 0; i < dim; i++) {
m[i] = BigInt(Math.floor(Math.random() * 1000000))
r[i] = BigInt(Math.floor(Math.random() * 1000000))
//console.log(m[i].toString(16), r[i].toString(16)),
}

// 生成生物特征编码的承诺
console.time('time')
let cmt = Array(dim)
const code = new Pedersen(g, h)
for(let i = 0; i < dim; i++) {
cmt[i] = code.Commitment(m[i], r[i])
//console.log(cmt[i].toString())
}
// 数据转化
let cmt_json = Array(dim)
let m_json = Array(dim)
let r_json = Array(dim)
for(let i = 0; i < dim; i++) {
cmt_json[i] = InttoHex(cmt[i], 16)
m_json[i] = InttoHex(m[i], 16)
r_json[i] = InttoHex(r[i], 16)
//console.log(cmt_json[i], m_json[i], r_json[i])
}
// 数据打包
const json = {
id: 'User',
m: m_json,
r: r_json,
cmt: cmt_json
}
const jsonString = JSON.stringify(json, null, 2);
// 数据存储
fs.writeFile('identity.json', jsonString, 'utf8', (err) => {
if (err) {
console.log("An error occured while writing JSON Object to File.");
return console.log(err);
}
console.log("Identity file has been saved.");
});
console.timeEnd('time')
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id" : "ca02b82d4f8abfef6186ac5b28d41a6703fe925e17c12164cbf9f634e0ffb9e2",
"m" : [ "895", "1085"],
"r" : [ "103333", "883370" ],
"cmt" : [ "53677044", "45537498" ]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 943338c

Please sign in to comment.