UNPKG

snarkyjs-elgamal

Version:

This repository implements Elgmal, a partial homomorphic encryption scheme originally described by [Taher Elgamal in 1985](https://caislab.kaist.ac.kr/lecture/2010/spring/cs548/basic/B02.pdf). This implementation includes the original version of Elgamal,

46 lines 1.96 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Field, SmartContract, state, State, method } from 'snarkyjs'; /** * Basic Example * See https://docs.minaprotocol.com/zkapps for more info. * * The Add contract initializes the state variable 'num' to be a Field(1) value by default when deployed. * When the 'update' method is called, the Add contract adds Field(2) to its 'num' contract state. * * This file is safe to delete and replace with your own contract. */ export class Add extends SmartContract { constructor() { super(...arguments); this.num = State(); } init() { super.init(); this.num.set(Field(1)); } update() { const currentState = this.num.get(); this.num.assertEquals(currentState); // precondition that links this.num.get() to the actual on-chain state const newState = currentState.add(2); this.num.set(newState); } } __decorate([ state(Field), __metadata("design:type", Object) ], Add.prototype, "num", void 0); __decorate([ method, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], Add.prototype, "update", null); //# sourceMappingURL=Add.js.map