From 42e5ed2c30a7ee529e541b365866d31f2a843e66 Mon Sep 17 00:00:00 2001 From: teddyjfpender Date: Thu, 21 Sep 2023 09:30:58 +0100 Subject: [PATCH] chore(fix things) --- .../contracts/KYCDepositCompliantContract.ts | 2 +- packages/data-model/package.json | 2 +- packages/data-model/src/data-model/README.md | 5 + packages/data-model/src/data-model/index.ts | 1 + .../src/data-model/src/dataModel.ts | 209 ++++++++++++++++++ .../data-model/src/data-model/src/index.ts | 2 + .../src/provable-programs/Transaction.ts | 170 ++++++++++++++ .../data-model/src/provable-programs/index.ts | 1 + .../src/data-model/src/utils/index.ts | 2 + .../src/data-model/src/utils/keyDerivation.ts | 24 ++ .../src/data-model/test/dataModel.test.ts | 106 +++++++++ .../test/test_vectors/testVectors.ts | 2 + packages/data-model/src/dataModel.ts | 2 +- packages/data-model/src/types.ts | 2 +- packages/data-model/src/utils/construction.ts | 2 +- packages/data-model/src/utils/conversion.ts | 2 +- .../src/utils/testCredentialUtil.ts | 2 +- packages/data-model/src/utils/verification.ts | 2 +- pnpm-lock.yaml | 19 +- 19 files changed, 547 insertions(+), 10 deletions(-) create mode 100644 packages/data-model/src/data-model/README.md create mode 100644 packages/data-model/src/data-model/index.ts create mode 100644 packages/data-model/src/data-model/src/dataModel.ts create mode 100644 packages/data-model/src/data-model/src/index.ts create mode 100644 packages/data-model/src/data-model/src/provable-programs/Transaction.ts create mode 100644 packages/data-model/src/data-model/src/provable-programs/index.ts create mode 100644 packages/data-model/src/data-model/src/utils/index.ts create mode 100644 packages/data-model/src/data-model/src/utils/keyDerivation.ts create mode 100644 packages/data-model/src/data-model/test/dataModel.test.ts create mode 100644 packages/data-model/src/data-model/test/test_vectors/testVectors.ts diff --git a/packages/credentials/test/contracts/KYCDepositCompliantContract.ts b/packages/credentials/test/contracts/KYCDepositCompliantContract.ts index e1a3c33..c6293de 100644 --- a/packages/credentials/test/contracts/KYCDepositCompliantContract.ts +++ b/packages/credentials/test/contracts/KYCDepositCompliantContract.ts @@ -1,4 +1,4 @@ -import { Field, SmartContract, state, State, method} from 'snarkyjs'; +import { Field, SmartContract, state, State, method, verify, VerificationKey} from 'snarkyjs'; import { KycProof } from '@herald-sdk/provable-programs'; /** * Basic Example for a counter zkApp with recursion diff --git a/packages/data-model/package.json b/packages/data-model/package.json index 4da678d..ea0193f 100644 --- a/packages/data-model/package.json +++ b/packages/data-model/package.json @@ -30,6 +30,6 @@ }, "dependencies": { "@jest/globals": "^29.6.2", - "snarkyjs": "^0.12.*" + "o1js": "^0.12.*" } } diff --git a/packages/data-model/src/data-model/README.md b/packages/data-model/src/data-model/README.md new file mode 100644 index 0000000..32d6316 --- /dev/null +++ b/packages/data-model/src/data-model/README.md @@ -0,0 +1,5 @@ +# Temporary + +This should be replaced when monorepo support with Bun is stable. + +```"@dark-matter/data-model": "workspace:*"``` \ No newline at end of file diff --git a/packages/data-model/src/data-model/index.ts b/packages/data-model/src/data-model/index.ts new file mode 100644 index 0000000..e6918d5 --- /dev/null +++ b/packages/data-model/src/data-model/index.ts @@ -0,0 +1 @@ +export * from './src' \ No newline at end of file diff --git a/packages/data-model/src/data-model/src/dataModel.ts b/packages/data-model/src/data-model/src/dataModel.ts new file mode 100644 index 0000000..be17cc2 --- /dev/null +++ b/packages/data-model/src/data-model/src/dataModel.ts @@ -0,0 +1,209 @@ +import { Poseidon, Struct, PublicKey, Group, Scalar, Provable, Field} from 'o1js'; + +interface EncryptedValueType { + publicKey: Group; + cipherText: Field[] +} + +export class EncryptedValue extends Struct({ + publicKey: Group, + cipherText: Provable.Array(Field, 255) // 255 is hardcoded for now, but we should change this to be dynamic... somehow... + }) implements EncryptedValueType { + constructor(publicKey: Group, cipherText: Field[]) { + + super({ publicKey: publicKey, cipherText: cipherText }); + } + toJSON(encryptedValue: EncryptedValueType) { + return { + publicKey: Group.toJSON(encryptedValue.publicKey), + cipherText: encryptedValue.cipherText.map((field) => field.toBigInt().toString()), + } + } + fromJSON(encryptedValue: any) { + const encryptedValueObject = JSON.parse(encryptedValue); + const publicKey = PublicKey.fromBase58(encryptedValueObject.publicKey).toGroup(); + const cipherText = encryptedValueObject.cipherText.map((field: string) => Field.from(field)); + return { publicKey, cipherText } as EncryptedValueType; + } + } + +/** + * Represents an unspent transaction output (UTXO) type. + */ +export interface UTXOType { + /** + * The one-time destination address, derived from the transaction secret and recipient view key. + */ + oneTimeAddress: PublicKey; + + /** + * Ephemeral public key used in the transaction. Typically denoted as R = r*G. + */ + ephemeralPublicKey: PublicKey; + + /** + * The amount of tokens in this UTXO. + */ + amount: Field; + + /** + * Token type or identifier. + */ + Token: Field; +} + +/** + * Represents an unspent transaction output (UTXO) in a blockchain-based system. + * Contains cryptographic details and amount associated with the UTXO. + */ +export class UTXO extends Struct({ + oneTimeAddress: PublicKey, + ephemeralPublicKey: PublicKey, + amount: Field, + Token: Field, + }) implements UTXOType { + + /** + * Constructs a UTXO object. + * @param publicSpendKey - The public spend key of the recipient. + * @param publicViewKey - The public view key of the recipient. + * @param amount - Amount of tokens in the UTXO. + * @param Token - Token type or identifier. + */ + constructor(publicSpendKey: PublicKey, publicViewKey: PublicKey, amount: Field, Token: Field) { + + // Generate a random private key for the transaction. + const r = Provable.witness(Scalar, () => Scalar.random()); + + // Compute the public key corresponding to r. This is R = r*G. + const R = PublicKey.fromGroup(Group.generator.scale(r)); + + // Compute the ephemeral key F. + const F = publicViewKey.toGroup().scale(r); + + // Calculate the shared secret ss = H(r*V) = H(v*R). + const ss = Scalar.from(Poseidon.hash(F.toFields()).toBigInt()); + + // Derive the one-time destination address, K. + const K = Group.generator.scale(ss.toBigInt()).add(publicSpendKey.toGroup()); + + super({ + oneTimeAddress: PublicKey.fromGroup(K), + ephemeralPublicKey: R, + amount: amount, + Token: Token, + }); + } + + /** + * Convert the UTXO object into its JSON representation. + * @param utxo - The UTXO object. + * @returns The JSON string representation of the UTXO. + */ + toJSON(utxo: UTXOType) { + return { + oneTimeAddress: PublicKey.toBase58(utxo.oneTimeAddress), + ephemeralPublicKey: PublicKey.toBase58(utxo.ephemeralPublicKey), + amount: utxo.amount.toBigInt().toString(), + } + } + + /** + * Convert a JSON string into a UTXO object. + * @param utxo - The JSON string representation of the UTXO. + * @returns The UTXO object. + */ + fromJSON(utxo: string) { + const utxoObject = JSON.parse(utxo); + const oneTimeAddress = PublicKey.fromBase58(utxoObject.oneTimeAddress); + const ephemeralPublicKey = PublicKey.fromBase58(utxoObject.ephemeralPublicKey); + const amount = Field.from(utxoObject.amount); + return { oneTimeAddress, ephemeralPublicKey, amount} as UTXOType; + } + } + +/** + * Represents the data structure of a limit order type which extends UTXO. + */ +export interface LimitOrderType extends UTXOType { + /** + * The quantity of tokens involved in the limit order. + */ + quantity: Field; + + /** + * The type or identifier of token the user wishes to swap for. + */ + tokenSwapFor: Field; + + /** + * The direction of the trade, either 'buy' or 'sell'. + */ + direction: Field; +} + +/** + * Represents a limit order in a decentralized exchange. + * Contains details about the trade and its associated UTXO. + */ +export class LimitOrder extends UTXO implements LimitOrderType { + quantity: Field; + tokenSwapFor: Field; + direction: Field; + + /** + * Constructs a LimitOrder object. + * @param utxoData - The UTXO associated with the limit order. + * @param quantity - Quantity of tokens involved in the order. + * @param tokenSwapFor - Type of token to be swapped. + * @param direction - Direction of the trade, 'buy' or 'sell'. + */ + constructor( + utxoData: UTXOType, + quantity: Field, + tokenSwapFor: Field, + direction: Field + ) { + super( + utxoData.oneTimeAddress, + utxoData.ephemeralPublicKey, + utxoData.amount, + utxoData.Token + ); + + this.quantity = quantity; + this.tokenSwapFor = tokenSwapFor; + this.direction = direction; + } + + /** + * Convert the LimitOrder object into its JSON representation. + * @returns The JSON string representation of the LimitOrder. + */ + override toJSON(): { oneTimeAddress: string; ephemeralPublicKey: string; amount: string; quantity: string; tokenSwapFor: string; direction: Field } { + const baseJSON = super.toJSON(this); + return { + ...baseJSON, + quantity: this.quantity.toBigInt().toString(), + tokenSwapFor: this.tokenSwapFor.toBigInt().toString(), + direction: this.direction + }; + } + + /** + * Convert a JSON string into a LimitOrder object. + * @param orderData - The JSON string representation of the LimitOrder. + * @returns The LimitOrder object. + */ + override fromJSON(orderData: string): LimitOrderType { + const orderObject = JSON.parse(orderData); + const baseUTXO = super.fromJSON(orderData); + + return { + ...baseUTXO, + quantity: Field.from(orderObject.quantity), + tokenSwapFor: Field.from(orderObject.tokenSwapFor), + direction: orderObject.direction + }; + } +} \ No newline at end of file diff --git a/packages/data-model/src/data-model/src/index.ts b/packages/data-model/src/data-model/src/index.ts new file mode 100644 index 0000000..947b1f4 --- /dev/null +++ b/packages/data-model/src/data-model/src/index.ts @@ -0,0 +1,2 @@ +export * from './dataModel' +export * from './utils' \ No newline at end of file diff --git a/packages/data-model/src/data-model/src/provable-programs/Transaction.ts b/packages/data-model/src/data-model/src/provable-programs/Transaction.ts new file mode 100644 index 0000000..74c2543 --- /dev/null +++ b/packages/data-model/src/data-model/src/provable-programs/Transaction.ts @@ -0,0 +1,170 @@ +import { Experimental, Group, Poseidon, PrivateKey, Provable, Scalar, Struct } from 'o1js'; +import { UTXO } from '../dataModel' + +/* +export function createTxArgs(input_length: number, output_length: number) { + return class TxArgs extends Struct({ + inputs: Provable.Array(UTXO, input_length), + outputs: Provable.Array(UTXO, output_length) + }) { + constructor(inputs: UTXO[], outputs: UTXO[]) { + super({ inputs, outputs }); + } + }; +} +*/ + +/** + * Represents the arguments used for constructing a transaction. + * Holds the necessary information for both inputs and outputs. + */ +export class TxArgs extends Struct({ + /** + * Transaction inputs. + * Note: Maximum of 2 inputs. + * + * @remarks We should thing about how to make this dynamic. If possible. + */ + inputs: Provable.Array(UTXO, 2), + + /** + * Transaction outputs. + * Note: Maximum of 2 outputs. + * + * @remarks We should thing about how to make this dynamic. If possible. + */ + outputs: Provable.Array(UTXO, 2), +}) { + + /** + * Constructs a `TxArgs` object. + * @param inputs - Array of UTXOs that act as inputs for the transaction. + * @param outputs - Array of UTXOs that act as outputs for the transaction. + */ + constructor(inputs: UTXO[], outputs: UTXO[]) { + super({ inputs, outputs }); + } + + /** + * Retrieve the transaction inputs. + * @returns Array of UTXOs used as inputs. + */ + getInputs() { + return this.inputs; + } + + /** + * Retrieve the transaction outputs. + * @returns Array of UTXOs used as outputs. + */ + getOutputs() { + return this.outputs; + } +} + +/** + * Represents the private arguments for a transaction. + * Holds cryptographic details that shouldn't be publicly visible. + */ + +export class PrivateTxArgs extends Struct({ + /** + * Shared secret scalars associated with transaction inputs. + */ + sharedSecretScalarInput: Provable.Array(Scalar, 2), + + /** + * The public view key of the sender. + */ + publicViewKey: Group, + + /** + * The public spend key of the sender. + */ + publicSpendKey: Group, +}) { + + /** + * Constructs a `PrivateTxArgs` object. + * @param txArgs - The public transaction arguments. + * @param privateSpendKey - The private spend key of the sender. + */ + constructor(txArgs: TxArgs, privateSpendKey: PrivateKey) { + const privateViewKey = PrivateKey.fromBigInt(Poseidon.hash(privateSpendKey.toFields()).toBigInt()); + // Function to compute shared secrets for an array of UTXOs + const computeSharedSecrets = (utxos: UTXO[]) => { + const ss: Scalar[] = []; + + for (const utxo of utxos) { + const R = utxo.ephemeralPublicKey + const scalarSs = Scalar.from(Poseidon.hash((R.toGroup().scale(privateViewKey.s)).toFields()).toBigInt()) + + ss.push(scalarSs); + } + + return { ss }; + } + + const { ss: ssInput } = computeSharedSecrets(txArgs.inputs as UTXO[]); + + super({ + sharedSecretScalarInput: ssInput, + publicViewKey: privateViewKey.toPublicKey().toGroup(), + publicSpendKey: privateSpendKey.toPublicKey().toGroup() + }); + } +} + + +/** + * Represents a Zero-Knowledge (ZK) program that constraints the spending of UTxOs. + * Contains methods that allow transaction validation and proving. + */ +export const Transaction = Experimental.ZkProgram({ + /** Public inputs of the transaction. */ + publicInput: TxArgs, + + /** Public outputs of the transaction. */ + publicOutput: TxArgs, + + methods: { + spend: { + /** Private inputs used for proving ownership and transaction validity. */ + privateInputs: [PrivateTxArgs], + + /** + * Execute the 'spend' transaction method. + * @param publicInputs - Public inputs for the transaction. + * @param privateInputs - Private inputs for the transaction. + * @returns The public inputs of the transaction. + */ + method(publicInputs: TxArgs, privateInputs: PrivateTxArgs): TxArgs { + + for (let i = 0; i < publicInputs.getInputs().length; i++) { + // Proving ownership of the input + const derivedOneTimeAddress = Group.generator.scale(privateInputs.sharedSecretScalarInput[i] as Scalar).add(privateInputs.publicSpendKey); + let input = publicInputs.getInputs()[i] as UTXO + derivedOneTimeAddress.assertEquals(input.oneTimeAddress.toGroup(), "Ownership proof failed for input " + i); + } + // Ensure value conservation + const valueInputs = publicInputs.getInputs().map((utxo) => utxo.amount).reduce((a, b) => a.add(b)); + const valueOutputs = publicInputs.getOutputs().map((utxo) => utxo.amount).reduce((a, b) => a.add(b)); + + valueInputs.assertEquals(valueOutputs, "Value conservation failed"); + + return publicInputs; + }, + }, + }, +}); + + + +/** + * Represents a proof for the `Transaction` ZkProgram. + * Holds necessary data for proving a transaction's validity without revealing private details. + */ +export class TransactionProof extends Experimental.ZkProgram.Proof(Transaction){ + static publicInput = this.prototype.publicInput; + static publicOutput = this.prototype.publicOutput; +}; \ No newline at end of file diff --git a/packages/data-model/src/data-model/src/provable-programs/index.ts b/packages/data-model/src/data-model/src/provable-programs/index.ts new file mode 100644 index 0000000..a925a5f --- /dev/null +++ b/packages/data-model/src/data-model/src/provable-programs/index.ts @@ -0,0 +1 @@ +export * from './Transaction' \ No newline at end of file diff --git a/packages/data-model/src/data-model/src/utils/index.ts b/packages/data-model/src/data-model/src/utils/index.ts new file mode 100644 index 0000000..415d48c --- /dev/null +++ b/packages/data-model/src/data-model/src/utils/index.ts @@ -0,0 +1,2 @@ +export * from './keyDerivation' +export * from './utils' \ No newline at end of file diff --git a/packages/data-model/src/data-model/src/utils/keyDerivation.ts b/packages/data-model/src/data-model/src/utils/keyDerivation.ts new file mode 100644 index 0000000..1acd3cc --- /dev/null +++ b/packages/data-model/src/data-model/src/utils/keyDerivation.ts @@ -0,0 +1,24 @@ +import { PrivateKey, Poseidon } from "o1js"; + +export type KeyPairs = { + s: string, + S: string, + v: string, + V: string +} + +export function deriveKeyPairs(privateKey: string): KeyPairs { + const privSpendKeyBase58 = privateKey; + // Derive the private view key from the private spend key using Poseidon hash. + const privViewKey = PrivateKey.fromBigInt(Poseidon.hash(PrivateKey.fromBase58(privSpendKeyBase58).toFields()).toBigInt()); + // Convert the private view key to its corresponding public view key. + const pubViewKey = privViewKey.toPublicKey(); + // Derive the public spend key from the private spend key. + const pubSpendKey = PrivateKey.fromBase58(privSpendKeyBase58).toPublicKey(); + return { + s: privSpendKeyBase58, + S: pubSpendKey.toBase58(), + v: privViewKey.toBase58(), + V: pubViewKey.toBase58() + } +} \ No newline at end of file diff --git a/packages/data-model/src/data-model/test/dataModel.test.ts b/packages/data-model/src/data-model/test/dataModel.test.ts new file mode 100644 index 0000000..10c1fa3 --- /dev/null +++ b/packages/data-model/src/data-model/test/dataModel.test.ts @@ -0,0 +1,106 @@ +import { describe, it, expect } from '@jest/globals'; +import { Encoding, Field, Poseidon, PrivateKey, PublicKey, verify } from 'o1js'; +import { KeyPairs, deriveKeyPairs } from '../src/utils/keyDerivation'; +import { PRIVATE_KEY_0, PRIVATE_KEY_1 } from './test_vectors/testVectors'; +import { UTXO } from '../src/dataModel'; +import { PrivateTxArgs, Transaction, TransactionProof, TxArgs } from '../src/provable-programs'; + + +/** + * Note: when running these tests + * ensure you provide a timeout, e.g.: bun test --timeout 500000 + */ +describe('UTXO Tests', () => { + let privSpendKeyBase58Sender: string; + let privSpendKeyBase58Receiver: string; + let keyPairsSender: KeyPairs; + let keyPairsReceiver: KeyPairs; + let amount: Field; + let token: Field; + + beforeEach(() => { + privSpendKeyBase58Sender = PRIVATE_KEY_0; + privSpendKeyBase58Receiver = PRIVATE_KEY_1; + keyPairsSender = deriveKeyPairs(privSpendKeyBase58Sender); + keyPairsReceiver = deriveKeyPairs(privSpendKeyBase58Receiver); + amount = Field(1_000_000); // or any number you choose + token = Poseidon.hash(Encoding.stringToFields('MINA')); + }); + it('should create a UTXO convert it to JSON and back', () => { + const utxo = new UTXO(PublicKey.fromBase58(keyPairsSender.S), PublicKey.fromBase58(keyPairsSender.V), amount, token); + expect(utxo).toBeDefined(); + const utxoJSON = UTXO.toJSON(utxo); + expect(utxoJSON).toBeDefined(); + const utxoFromJSON = UTXO.fromJSON(utxoJSON); + expect(utxoFromJSON).toBeDefined(); + expect(utxoFromJSON.oneTimeAddress).toEqual(utxo.oneTimeAddress); + }); + it('should create a transaction with 2 inputs and 2 outputs', () => { + // Create 2 UTXOs -- these are spendable b + const utxo1 = new UTXO(PublicKey.fromBase58(keyPairsSender.S), PublicKey.fromBase58(keyPairsSender.V), amount, token); + const utxo2 = new UTXO(PublicKey.fromBase58(keyPairsSender.S), PublicKey.fromBase58(keyPairsSender.V), amount, token); + + // Create 2 outputs + const output1 = new UTXO(PublicKey.fromBase58(keyPairsSender.S), PublicKey.fromBase58(keyPairsSender.V), amount, token); + const output2 = new UTXO(PublicKey.fromBase58(keyPairsSender.S), PublicKey.fromBase58(keyPairsSender.V), amount, token); + + // Create a transaction public inputs and outputs + const tx = new TxArgs([utxo1, utxo2], [output1, output2]); + expect(tx).toBeDefined(); + expect(tx.inputs.length).toEqual(2); + expect(tx.outputs.length).toEqual(2); + + // Create a transaction private inputs + const txPrivateArgs = new PrivateTxArgs(tx, PrivateKey.fromBase58(keyPairsSender.v)); + expect(txPrivateArgs).toBeDefined(); + expect(txPrivateArgs.sharedSecretScalarInput.length).toEqual(2); + }); + + it('should create a transaction with 2 inputs and 2 outputs, compile the transaction program and proof should be valid', async () => { + // Create 2 UTXOs -- these are spendable by the sender + const utxo1 = new UTXO(PublicKey.fromBase58(keyPairsSender.S), PublicKey.fromBase58(keyPairsSender.V), Field(100), token); + const utxo2 = new UTXO(PublicKey.fromBase58(keyPairsSender.S), PublicKey.fromBase58(keyPairsSender.V), Field(50), token); + + // Create 2 outputs + const output1 = new UTXO(PublicKey.fromBase58(keyPairsReceiver.S), PublicKey.fromBase58(keyPairsReceiver.V), Field(140), token); + const output2 = new UTXO(PublicKey.fromBase58(keyPairsReceiver.S), PublicKey.fromBase58(keyPairsReceiver.V), Field(10), token); + + // Create a transaction public inputs and outputs + const tx = new TxArgs([utxo1, utxo2], [output1, output2]); + expect(tx).toBeDefined(); + expect(tx.inputs.length).toEqual(2); + expect(tx.outputs.length).toEqual(2); + + // Create a transaction private inputs + const txPrivateArgs = new PrivateTxArgs(tx, PrivateKey.fromBase58(keyPairsSender.s)); + expect(txPrivateArgs).toBeDefined(); + expect(txPrivateArgs.sharedSecretScalarInput.length).toEqual(2); + + // Compile the transaction program + console.log('Compiling the transaction program...'); + const { verificationKey } = await Transaction.compile(); + console.log('Transaction program compiled successfully.'); + + // Create a proof + console.log('Creating a proof...'); + const startTime = new Date().getTime(); // Record the start time + const proof = await Transaction.spend(tx, txPrivateArgs) as TransactionProof; + const endTime = new Date().getTime(); // Record the end time + console.log('Proof created. Time taken: ' + (endTime - startTime) + 'ms'); + + // Verify the proof + console.log('Verifying the proof...'); + const result = await verify(proof, verificationKey); + expect(result).toBeTruthy(); + + // Check the proof inputs and outputs + const inputs = proof.publicInput.inputs as UTXO[]; + const outputs = proof.publicInput.outputs as UTXO[]; + expect(inputs.length).toEqual(2); + expect(outputs.length).toEqual(2); + expect(inputs[0]?.oneTimeAddress).toEqual(utxo1.oneTimeAddress); + expect(inputs[1]?.oneTimeAddress).toEqual(utxo2.oneTimeAddress); + expect(outputs[0]?.oneTimeAddress).toEqual(output1.oneTimeAddress); + expect(outputs[1]?.oneTimeAddress).toEqual(output2.oneTimeAddress); + }); +}); \ No newline at end of file diff --git a/packages/data-model/src/data-model/test/test_vectors/testVectors.ts b/packages/data-model/src/data-model/test/test_vectors/testVectors.ts new file mode 100644 index 0000000..6596772 --- /dev/null +++ b/packages/data-model/src/data-model/test/test_vectors/testVectors.ts @@ -0,0 +1,2 @@ +export const PRIVATE_KEY_0 = "EKE1h2CEeYQxDaPfjSGNNB83tXYSpn3Cqt6B3vLBHuLixZLApCpd" +export const PRIVATE_KEY_1 = "EKEU31uonuF2rhG5f8KW4hRseqDjpPVysqcfKCKxqvs7x5oRviN1" \ No newline at end of file diff --git a/packages/data-model/src/dataModel.ts b/packages/data-model/src/dataModel.ts index 87c94df..a4e0b0c 100644 --- a/packages/data-model/src/dataModel.ts +++ b/packages/data-model/src/dataModel.ts @@ -1,4 +1,4 @@ -import { Field, PrivateKey, Signature, MerkleMap, Struct, MerkleMapWitness } from 'snarkyjs'; +import { Field, PrivateKey, Signature, MerkleMap, Struct, MerkleMapWitness } from 'o1js'; import { stringToField, claimToField, numberToField } from './utils'; import { ClaimType } from './types.js'; diff --git a/packages/data-model/src/types.ts b/packages/data-model/src/types.ts index 6030e87..2a40d8c 100644 --- a/packages/data-model/src/types.ts +++ b/packages/data-model/src/types.ts @@ -1,3 +1,3 @@ -import { PublicKey } from "snarkyjs"; +import { PublicKey } from "o1js"; export type ClaimType = string | number | PublicKey; diff --git a/packages/data-model/src/utils/construction.ts b/packages/data-model/src/utils/construction.ts index 5dacd89..93af2b5 100644 --- a/packages/data-model/src/utils/construction.ts +++ b/packages/data-model/src/utils/construction.ts @@ -1,4 +1,4 @@ -import { PrivateKey } from "snarkyjs"; +import { PrivateKey } from "o1js"; import { Claim, SignedClaim, CredentialPresentation } from "../dataModel"; import { ClaimType } from "../types"; diff --git a/packages/data-model/src/utils/conversion.ts b/packages/data-model/src/utils/conversion.ts index 6f57736..47ed791 100644 --- a/packages/data-model/src/utils/conversion.ts +++ b/packages/data-model/src/utils/conversion.ts @@ -1,4 +1,4 @@ -import { Field, Encoding, Poseidon, PublicKey } from "snarkyjs"; +import { Field, Encoding, Poseidon, PublicKey } from "o1js"; import { ClaimType } from "../types"; //let {toBytes, fromBytes} = Encoding.Bijective.Fp; diff --git a/packages/data-model/src/utils/testCredentialUtil.ts b/packages/data-model/src/utils/testCredentialUtil.ts index 039da96..0e038f2 100644 --- a/packages/data-model/src/utils/testCredentialUtil.ts +++ b/packages/data-model/src/utils/testCredentialUtil.ts @@ -1,4 +1,4 @@ -import { PublicKey } from "snarkyjs"; +import { PublicKey } from "o1js"; import { ClaimType } from "../types" import { flattenObject } from "./conversion"; diff --git a/packages/data-model/src/utils/verification.ts b/packages/data-model/src/utils/verification.ts index 9c3a20f..e1bfbc1 100644 --- a/packages/data-model/src/utils/verification.ts +++ b/packages/data-model/src/utils/verification.ts @@ -1,4 +1,4 @@ -import { Field, PublicKey } from "snarkyjs"; +import { Field, PublicKey } from "o1js"; import { Claim, CredentialPresentation } from "../dataModel"; /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8d8a25d..7d85fd0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -142,9 +142,9 @@ importers: '@jest/globals': specifier: ^29.6.2 version: 29.6.2 - snarkyjs: + o1js: specifier: ^0.12.* - version: 0.12.1 + version: 0.12.2 devDependencies: '@herald-sdk/common': specifier: '*' @@ -5905,6 +5905,21 @@ packages: engines: {node: '>=6.0.0'} dev: false + /o1js@0.12.2: + resolution: {integrity: sha512-DkGw2sqj2t8lXSZFhv7qQnkG7WEhL4VrHYCpIagckmt6xH1A9weJo1SUqFXRRko9zeWY1e76jy/+SocrEUS5Gw==} + engines: {node: '>=16.4.0'} + hasBin: true + dependencies: + blakejs: 1.2.1 + detect-gpu: 5.0.35 + isomorphic-fetch: 3.0.0 + js-sha256: 0.9.0 + reflect-metadata: 0.1.13 + tslib: 2.5.0 + transitivePeerDependencies: + - encoding + dev: false + /object-assign@4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'}