Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Rollup warnings #937

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default networks.map((network) => {
// Used by the SDK
"comlink",
`@provablehq/wasm/${network}.js`,
"core-js/proposals/json-parse-with-source.js",
],
plugins: [
replace({
Expand Down
5 changes: 5 additions & 0 deletions sdk/rollup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export default networks.map((network) => {
// Used by the SDK
"comlink",
`@provablehq/wasm/${network}.js`,
"core-js/proposals/json-parse-with-source.js",

// Used by tests
"chai",
"sinon",
],
plugins: [
replace({
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ViewKey,
PrivateKeyCiphertext,
RecordCiphertext,
} from "./browser";
} from "./wasm";

interface AccountParam {
privateKey?: string;
Expand Down
140 changes: 16 additions & 124 deletions sdk/src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,116 +1,4 @@
import "./polyfill/shared";
import {VerifyingKey, Metadata} from "@provablehq/wasm/%%NETWORK%%.js";

const KEY_STORE = Metadata.baseUrl();

interface Key {
name: string,
locator: string,
prover: string,
verifier: string,
verifyingKey: () => VerifyingKey,
}

function convert(metadata: Metadata): Key {
// This looks up the method name in VerifyingKey
const verifyingKey = (VerifyingKey as any)[metadata.verifyingKey];

if (!verifyingKey) {
throw new Error("Invalid method name: " + metadata.verifyingKey);
}

return {
name: metadata.name,
locator: metadata.locator,
prover: metadata.prover,
verifier: metadata.verifier,
verifyingKey,
};
}

const CREDITS_PROGRAM_KEYS = {
bond_public: convert(Metadata.bond_public()),
bond_validator: convert(Metadata.bond_validator()),
claim_unbond_public: convert(Metadata.claim_unbond_public()),
fee_private: convert(Metadata.fee_private()),
fee_public: convert(Metadata.fee_public()),
inclusion: convert(Metadata.inclusion()),
join: convert(Metadata.join()),
set_validator_state: convert(Metadata.set_validator_state()),
split: convert(Metadata.split()),
transfer_private: convert(Metadata.transfer_private()),
transfer_private_to_public: convert(Metadata.transfer_private_to_public()),
transfer_public: convert(Metadata.transfer_public()),
transfer_public_as_signer: convert(Metadata.transfer_public_as_signer()),
transfer_public_to_private: convert(Metadata.transfer_public_to_private()),
unbond_public: convert(Metadata.unbond_public()),
getKey: function(key: string): Key {
if (this.hasOwnProperty(key)) {
return (this as any)[key] as Key;
} else {
throw new Error(`Key "${key}" not found.`);
}
}
};

const PRIVATE_TRANSFER_TYPES = new Set([
"transfer_private",
"private",
"transferPrivate",
"transfer_private_to_public",
"privateToPublic",
"transferPrivateToPublic",
]);
const VALID_TRANSFER_TYPES = new Set([
"transfer_private",
"private",
"transferPrivate",
"transfer_private_to_public",
"privateToPublic",
"transferPrivateToPublic",
"transfer_public",
"transfer_public_as_signer",
"public",
"public_as_signer",
"transferPublic",
"transferPublicAsSigner",
"transfer_public_to_private",
"publicToPrivate",
"publicAsSigner",
"transferPublicToPrivate",
]);
const PRIVATE_TRANSFER = new Set([
"private",
"transfer_private",
"transferPrivate",
]);
const PRIVATE_TO_PUBLIC_TRANSFER = new Set([
"private_to_public",
"privateToPublic",
"transfer_private_to_public",
"transferPrivateToPublic",
]);
const PUBLIC_TRANSFER = new Set([
"public",
"transfer_public",
"transferPublic",
]);
const PUBLIC_TRANSFER_AS_SIGNER = new Set([
"public_as_signer",
"transfer_public_as_signer",
"transferPublicAsSigner",
]);
const PUBLIC_TO_PRIVATE_TRANSFER = new Set([
"public_to_private",
"publicToPrivate",
"transfer_public_to_private",
"transferPublicToPrivate",
]);

function logAndThrow(message: string): never {
console.error(message);
throw new Error(message);
}

import { Account } from "./account";
import { AleoNetworkClient, ProgramImports } from "./network-client";
Expand Down Expand Up @@ -149,6 +37,8 @@ export { createAleoWorker } from "./managed-worker";

export { ProgramManager } from "./program-manager";

export { logAndThrow } from "./utils";

export {
Address,
Execution as FunctionExecution,
Expand All @@ -168,10 +58,23 @@ export {
ViewKey,
initThreadPool,
verifyFunctionExecution,
} from "@provablehq/wasm/%%NETWORK%%.js";
} from "./wasm";

export { initializeWasm };

export {
Key,
CREDITS_PROGRAM_KEYS,
KEY_STORE,
PRIVATE_TRANSFER,
PRIVATE_TO_PUBLIC_TRANSFER,
PRIVATE_TRANSFER_TYPES,
PUBLIC_TRANSFER,
PUBLIC_TRANSFER_AS_SIGNER,
PUBLIC_TO_PRIVATE_TRANSFER,
VALID_TRANSFER_TYPES,
} from "./constants";

export {
Account,
AleoKeyProvider,
Expand All @@ -185,7 +88,6 @@ export {
FunctionKeyPair,
FunctionKeyProvider,
Input,
Key,
KeySearchParams,
NetworkRecordProvider,
ProgramImports,
Expand All @@ -196,14 +98,4 @@ export {
RecordSearchParams,
TransactionModel,
Transition,
CREDITS_PROGRAM_KEYS,
KEY_STORE,
PRIVATE_TRANSFER,
PRIVATE_TO_PUBLIC_TRANSFER,
PRIVATE_TRANSFER_TYPES,
PUBLIC_TRANSFER,
PUBLIC_TRANSFER_AS_SIGNER,
PUBLIC_TO_PRIVATE_TRANSFER,
VALID_TRANSFER_TYPES,
logAndThrow,
};
113 changes: 113 additions & 0 deletions sdk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import {VerifyingKey, Metadata} from "./wasm";

export const KEY_STORE = Metadata.baseUrl();

export interface Key {
name: string,
locator: string,
prover: string,
verifier: string,
verifyingKey: () => VerifyingKey,
}

function convert(metadata: Metadata): Key {
// This looks up the method name in VerifyingKey
const verifyingKey = (VerifyingKey as any)[metadata.verifyingKey];

if (!verifyingKey) {
throw new Error("Invalid method name: " + metadata.verifyingKey);
}

return {
name: metadata.name,
locator: metadata.locator,
prover: metadata.prover,
verifier: metadata.verifier,
verifyingKey,
};
}

export const CREDITS_PROGRAM_KEYS = {
bond_public: convert(Metadata.bond_public()),
bond_validator: convert(Metadata.bond_validator()),
claim_unbond_public: convert(Metadata.claim_unbond_public()),
fee_private: convert(Metadata.fee_private()),
fee_public: convert(Metadata.fee_public()),
inclusion: convert(Metadata.inclusion()),
join: convert(Metadata.join()),
set_validator_state: convert(Metadata.set_validator_state()),
split: convert(Metadata.split()),
transfer_private: convert(Metadata.transfer_private()),
transfer_private_to_public: convert(Metadata.transfer_private_to_public()),
transfer_public: convert(Metadata.transfer_public()),
transfer_public_as_signer: convert(Metadata.transfer_public_as_signer()),
transfer_public_to_private: convert(Metadata.transfer_public_to_private()),
unbond_public: convert(Metadata.unbond_public()),
getKey: function(key: string): Key {
if (this.hasOwnProperty(key)) {
return (this as any)[key] as Key;
} else {
throw new Error(`Key "${key}" not found.`);
}
}
};

export const PRIVATE_TRANSFER_TYPES = new Set([
"transfer_private",
"private",
"transferPrivate",
"transfer_private_to_public",
"privateToPublic",
"transferPrivateToPublic",
]);

export const VALID_TRANSFER_TYPES = new Set([
"transfer_private",
"private",
"transferPrivate",
"transfer_private_to_public",
"privateToPublic",
"transferPrivateToPublic",
"transfer_public",
"transfer_public_as_signer",
"public",
"public_as_signer",
"transferPublic",
"transferPublicAsSigner",
"transfer_public_to_private",
"publicToPrivate",
"publicAsSigner",
"transferPublicToPrivate",
]);

export const PRIVATE_TRANSFER = new Set([
"private",
"transfer_private",
"transferPrivate",
]);

export const PRIVATE_TO_PUBLIC_TRANSFER = new Set([
"private_to_public",
"privateToPublic",
"transfer_private_to_public",
"transferPrivateToPublic",
]);

export const PUBLIC_TRANSFER = new Set([
"public",
"transfer_public",
"transferPublic",
]);

export const PUBLIC_TRANSFER_AS_SIGNER = new Set([
"public_as_signer",
"transfer_public_as_signer",
"transferPublicAsSigner",
]);

export const PUBLIC_TO_PRIVATE_TRANSFER = new Set([
"public_to_private",
"publicToPrivate",
"transfer_public_to_private",
"transferPublicToPrivate",
]);
12 changes: 8 additions & 4 deletions sdk/src/function-key-provider.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import {
ProvingKey,
VerifyingKey,
CREDITS_PROGRAM_KEYS,
KEY_STORE,
Key,
PRIVATE_TRANSFER,
PRIVATE_TO_PUBLIC_TRANSFER,
PUBLIC_TRANSFER,
PUBLIC_TO_PRIVATE_TRANSFER,
PUBLIC_TRANSFER_AS_SIGNER
} from "./browser";
PUBLIC_TRANSFER_AS_SIGNER,
} from "./constants";

import {
ProvingKey,
VerifyingKey,
} from "./wasm";

import { get } from "./utils";

type FunctionKeyPair = [ProvingKey, VerifyingKey];
Expand Down
11 changes: 5 additions & 6 deletions sdk/src/network-client.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { get, post, parseJSON } from "./utils";
import { get, post, parseJSON, logAndThrow } from "./utils";
import { Account } from "./account";
import { Block } from "./models/block";
import { TransactionModel } from "./models/transactionModel";
import {
Account,
Block,
RecordCiphertext,
Program,
RecordPlaintext,
PrivateKey,
Transaction,
TransactionModel,
logAndThrow
} from "./browser";
} from "./wasm";

type ProgramImports = { [key: string]: string | Program };

Expand Down
14 changes: 10 additions & 4 deletions sdk/src/offline-key-provider.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import {
CachedKeyPair,
FunctionKeyPair,
FunctionKeyProvider,
KeySearchParams,
FunctionKeyPair,
CachedKeyPair,
} from "./function-key-provider";

import {
ProvingKey,
VerifyingKey,
} from "./wasm";

import {
CREDITS_PROGRAM_KEYS,
PRIVATE_TRANSFER,
PRIVATE_TO_PUBLIC_TRANSFER,
PUBLIC_TRANSFER,
PUBLIC_TO_PRIVATE_TRANSFER,
PUBLIC_TRANSFER_AS_SIGNER
} from "./browser";
PUBLIC_TRANSFER_AS_SIGNER,
} from "./constants";

/**
* Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes
Expand Down
Loading
Loading