@aztec/foundation
Advanced tools
Comparing version 0.1.0-alpha59 to 0.1.0-alpha60
@@ -1,2 +0,2 @@ | ||
import { FunctionAbi } from '@aztec/foundation/abi'; | ||
import { ABIParameter, FunctionAbi } from '@aztec/foundation/abi'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
@@ -16,2 +16,28 @@ /** | ||
export declare function decodeReturnValues(abi: FunctionAbi, returnValues: Fr[]): DecodedReturn; | ||
/** | ||
* Decodes the signature of a function from the name and parameters. | ||
*/ | ||
export declare class FunctionSignatureDecoder { | ||
private name; | ||
private parameters; | ||
constructor(name: string, parameters: ABIParameter[]); | ||
/** | ||
* Decodes a single function parameter for the function signature. | ||
* @param param - The parameter to decode. | ||
* @returns A string representing the parameter type. | ||
*/ | ||
private decodeParameter; | ||
/** | ||
* Decodes all the parameters and build the function signature | ||
* @returns The function signature. | ||
*/ | ||
decode(): string; | ||
} | ||
/** | ||
* Decodes a function signature from the name and parameters. | ||
* @param name - The name of the function- | ||
* @param parameters - The parameters of the function. | ||
* @returns - The function signature. | ||
*/ | ||
export declare function decodeFunctionSignature(name: string, parameters: ABIParameter[]): string; | ||
//# sourceMappingURL=decoder.d.ts.map |
@@ -80,2 +80,51 @@ /** | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVjb2Rlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hYmkvZGVjb2Rlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFRQTs7O0dBR0c7QUFDSCxNQUFNLG1CQUFtQjtJQUN2QixZQUFvQixHQUFnQixFQUFVLFNBQWU7UUFBekMsUUFBRyxHQUFILEdBQUcsQ0FBYTtRQUFVLGNBQVMsR0FBVCxTQUFTLENBQU07SUFBRyxDQUFDO0lBRWpFOzs7O09BSUc7SUFDSyxZQUFZLENBQUMsT0FBZ0I7UUFDbkMsUUFBUSxPQUFPLENBQUM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(name, parameters) { | ||
this.name = name; | ||
this.parameters = parameters; | ||
} | ||
/** | ||
* Decodes a single function parameter for the function signature. | ||
* @param param - The parameter to decode. | ||
* @returns A string representing the parameter type. | ||
*/ | ||
decodeParameter(param) { | ||
switch (param.kind) { | ||
case 'field': | ||
return 'Field'; | ||
case 'integer': | ||
if (param.sign === 'signed') { | ||
throw new Error('Unsupported type: signed integer'); | ||
} | ||
return `u${param.width}`; | ||
case 'boolean': | ||
return 'bool'; | ||
case 'array': | ||
return `[${this.decodeParameter(param.type)};${param.length}]`; | ||
case 'struct': | ||
return `(${param.fields.map(field => `${this.decodeParameter(field.type)}`).join(',')})`; | ||
default: | ||
throw new Error(`Unsupported type: ${param.kind}`); | ||
} | ||
} | ||
/** | ||
* Decodes all the parameters and build the function signature | ||
* @returns The function signature. | ||
*/ | ||
decode() { | ||
return `${this.name}(${this.parameters.map(param => this.decodeParameter(param.type)).join(',')})`; | ||
} | ||
} | ||
/** | ||
* Decodes a function signature from the name and parameters. | ||
* @param name - The name of the function- | ||
* @param parameters - The parameters of the function. | ||
* @returns - The function signature. | ||
*/ | ||
export function decodeFunctionSignature(name, parameters) { | ||
return new FunctionSignatureDecoder(name, parameters).decode(); | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVjb2Rlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hYmkvZGVjb2Rlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFRQTs7O0dBR0c7QUFDSCxNQUFNLG1CQUFtQjtJQUN2QixZQUFvQixHQUFnQixFQUFVLFNBQWU7UUFBekMsUUFBRyxHQUFILEdBQUcsQ0FBYTtRQUFVLGNBQVMsR0FBVCxTQUFTLENBQU07SUFBRyxDQUFDO0lBRWpFOzs7O09BSUc7SUFDSyxZQUFZLENBQUMsT0FBZ0I7UUFDbkMsUUFBUSxPQUFPLENBQUMsSUFB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VSxDQUFDLEdBQUcsQ0FBQyxLQUFLLENBQUMsRUFBRSxDQUFDLElBQUksQ0FBQyxlQUFlLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUM7SUFDckcsQ0FBQztDQUNGO0FBRUQ7Ozs7O0dBS0c7QUFDSCxNQUFNLFVBQVUsdUJBQXVCLENBQUMsSUFBWSxFQUFFLFVBQTBCO0lBQzlFLE9BQU8sSUFBSSx3QkFBd0IsQ0FBQyxJQUFJLEVBQUUsVUFBVSxDQUFDLENBQUMsTUFBTSxFQUFFLENBQUM7QUFDakUsQ0FBQyJ9 |
@@ -0,1 +1,2 @@ | ||
import { decodeFunctionSignature } from '@aztec/foundation/abi'; | ||
import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer'; | ||
@@ -85,4 +86,7 @@ import { keccak } from '@aztec/foundation/crypto'; | ||
static fromNameAndParameters(name, parameters) { | ||
const signature = name === 'constructor' ? name : `${name}(${parameters.map(p => p.type.kind).join(',')})`; | ||
return FunctionSelector.fromSignature(signature); | ||
const signature = decodeFunctionSignature(name, parameters); | ||
const selector = FunctionSelector.fromSignature(signature); | ||
// If using the debug logger here it kill the typing in the `server_world_state_synchroniser` and jest tests. | ||
// console.log(`Function selector for ${signature} is ${selector}`); | ||
return selector; | ||
} | ||
@@ -101,2 +105,2 @@ /** | ||
FunctionSelector.SIZE = 4; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZnVuY3Rpb25fc2VsZWN0b3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYWJpL2Z1bmN0aW9uX3NlbGVjdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxVQUFVLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDekUsT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FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUM7SUFDNUIsQ0FBQztJQUVEOzs7O09BSUc7SUFDSCxNQUFNLENBQUMsU0FBUyxDQUFDLEVBQU07UUFDckIsT0FBTyxJQUFJLGdCQUFnQixDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQztJQUNoRCxDQUFDO0lBRUQ7Ozs7T0FJRztJQUNILE1BQU0sQ0FBQyxhQUFhLENBQUMsU0FBaUI7UUFDcEMsT0FBTyxnQkFBZ0IsQ0FBQyxVQUFVLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUMsQ0FBQyxRQUFRLENBQUMsQ0FBQyxFQUFFLGdCQUFnQixDQUFDLElBQUksQ0FBQyxDQUFDLENBQUM7SUFDeEcsQ0FBQztJQUVEOzs7OztPQUtHO0lBQ0gsTUFBTSxDQUFDLHFCQUFxQixDQUFDLElBQVksRUFBRSxVQUEwQjtRQUNuRSxNQUFNLFNBQVMsR0FBRyx1QkFBdUIsQ0FBQyxJQUFJLEVBQUUsVUFBVSxDQUFDLENBQUM7UUFDNUQsTUFBTSxRQUFRLEdBQUcsZ0JBQWdCLENBQUMsYUFBYSxDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQzNELDZHQUE2RztRQUM3RyxvRUFBb0U7UUFDcEUsT0FBTyxRQUFRLENBQUM7SUFDbEIsQ0FBQztJQUVEOzs7T0FHRztJQUNILE1BQU0sQ0FBQyxLQUFLO1FBQ1YsT0FBTyxJQUFJLGdCQUFnQixDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ2pDLENBQUM7O0FBdEdEOztHQUVHO0FBQ1cscUJBQUksR0FBRyxDQUFDLENBQUMifQ== |
@@ -84,3 +84,3 @@ import { Buffer } from 'buffer'; | ||
// Is this a dictionary? | ||
if (obj.constructor === Object) { | ||
if (typeof obj === 'object') { | ||
const newObj = {}; | ||
@@ -123,17 +123,19 @@ for (const key of Object.keys(obj)) { | ||
} | ||
// Is this a dictionary? | ||
if (obj.constructor === Object) { | ||
const newObj = {}; | ||
for (const key of Object.keys(obj)) { | ||
newObj[key] = convertToJsonObj(cc, obj[key]); | ||
if (typeof obj === 'object') { | ||
// Is this a dictionary? | ||
if (isPlainObject(obj)) { | ||
const newObj = {}; | ||
for (const key of Object.keys(obj)) { | ||
newObj[key] = convertToJsonObj(cc, obj[key]); | ||
} | ||
return newObj; | ||
} | ||
return newObj; | ||
else { | ||
// Throw if this is a non-primitive class that was not registered | ||
throw new Error(`Object ${obj.constructor.name} not registered for serialisation`); | ||
} | ||
} | ||
// Throw if this is a non-primitive class that was not registered | ||
if (typeof obj === 'object' && !isPlainObject(obj)) { | ||
throw new Error(`Object ${obj.constructor.name} not registered for serialisation`); | ||
} | ||
// Leave alone, assume JSON primitive | ||
return obj; | ||
} | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udmVydC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9qc29uLXJwYy9jb252ZXJ0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSxRQUFRLENBQUM7QUFDaEMsT0FBTyxhQUFhLE1BQU0sc0JBQXNCLENBQUM7QUFJakQ7Ozs7R0FJRztBQUNILFNBQVMsYUFBYSxDQUFDLEdBQVE7SUFDN0IsSUFBSSxHQUFHLEtBQUssSUFBSSxFQUFFO1FBQ2hCLE9BQU8sS0FBSyxDQUFDO0tBQ2Q7SUFFRCxJQUFJLEtBQUssR0FBRyxHQUFHLENBQUM7SUFDaEIsSUFBSSxPQUFPLEdBQUcsQ0FBQyxDQUFDO0lBQ2hCLE1BQU0sMEJBQTBCLEdBQUcsSUFBSSxDQUFDLENBQUMsbUJBQW1CO0lBQzVELE9BQU8sTUFBTSxDQ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IsT0FBTyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBTSxFQUFFLEVBQUUsQ0FBQyxnQkFBZ0IsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQztLQUNyRDtJQUVELElBQUksT0FBTyxHQUFHLEtBQUssUUFBUSxFQUFFO1FBQzNCLHdCQUF3QjtRQUN4QixJQUFJLGFBQWEsQ0FBQyxHQUFHLENBQUMsRUFBRTtZQUN0QixNQUFNLE1BQU0sR0FBUSxFQUFFLENBQUM7WUFDdkIsS0FBSyxNQUFNLEdBQUcsSUFBSSxNQUFNLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFO2dCQUNsQyxNQUFNLENBQUMsR0FBRyxDQUFDLEdBQUcsZ0JBQWdCLENBQUMsRUFBRSxFQUFFLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDO2FBQzlDO1lBQ0QsT0FBTyxNQUFNLENBQUM7U0FDZjthQUFNO1lBQ0wsaUVBQWlFO1lBQ2pFLE1BQU0sSUFBSSxLQUFLLENBQUMsVUFBVSxHQUFHLENBQUMsV0FBVyxDQUFDLElBQUksbUNBQW1DLENBQUMsQ0FBQztTQUNwRjtLQUNGO0lBRUQscUNBQXFDO0lBQ3JDLE9BQU8sR0FBRyxDQUFDO0FBQ2IsQ0FBQyJ9 |
{ | ||
"name": "@aztec/foundation", | ||
"version": "0.1.0-alpha59", | ||
"version": "0.1.0-alpha60", | ||
"exports": { | ||
@@ -5,0 +5,0 @@ "./eslint": "./.eslintrc.cjs", |
@@ -1,2 +0,2 @@ | ||
import { ABIType, FunctionAbi } from '@aztec/foundation/abi'; | ||
import { ABIParameter, ABIType, FunctionAbi } from '@aztec/foundation/abi'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
@@ -89,1 +89,51 @@ | ||
} | ||
/** | ||
* Decodes the signature of a function from the name and parameters. | ||
*/ | ||
export class FunctionSignatureDecoder { | ||
constructor(private name: string, private parameters: ABIParameter[]) {} | ||
/** | ||
* Decodes a single function parameter for the function signature. | ||
* @param param - The parameter to decode. | ||
* @returns A string representing the parameter type. | ||
*/ | ||
private decodeParameter(param: ABIType): string { | ||
switch (param.kind) { | ||
case 'field': | ||
return 'Field'; | ||
case 'integer': | ||
if (param.sign === 'signed') { | ||
throw new Error('Unsupported type: signed integer'); | ||
} | ||
return `u${param.width}`; | ||
case 'boolean': | ||
return 'bool'; | ||
case 'array': | ||
return `[${this.decodeParameter(param.type)};${param.length}]`; | ||
case 'struct': | ||
return `(${param.fields.map(field => `${this.decodeParameter(field.type)}`).join(',')})`; | ||
default: | ||
throw new Error(`Unsupported type: ${param.kind}`); | ||
} | ||
} | ||
/** | ||
* Decodes all the parameters and build the function signature | ||
* @returns The function signature. | ||
*/ | ||
public decode(): string { | ||
return `${this.name}(${this.parameters.map(param => this.decodeParameter(param.type)).join(',')})`; | ||
} | ||
} | ||
/** | ||
* Decodes a function signature from the name and parameters. | ||
* @param name - The name of the function- | ||
* @param parameters - The parameters of the function. | ||
* @returns - The function signature. | ||
*/ | ||
export function decodeFunctionSignature(name: string, parameters: ABIParameter[]) { | ||
return new FunctionSignatureDecoder(name, parameters).decode(); | ||
} |
@@ -1,2 +0,2 @@ | ||
import { ABIParameter } from '@aztec/foundation/abi'; | ||
import { ABIParameter, decodeFunctionSignature } from '@aztec/foundation/abi'; | ||
import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer'; | ||
@@ -100,4 +100,7 @@ import { keccak } from '@aztec/foundation/crypto'; | ||
static fromNameAndParameters(name: string, parameters: ABIParameter[]) { | ||
const signature = name === 'constructor' ? name : `${name}(${parameters.map(p => p.type.kind).join(',')})`; | ||
return FunctionSelector.fromSignature(signature); | ||
const signature = decodeFunctionSignature(name, parameters); | ||
const selector = FunctionSelector.fromSignature(signature); | ||
// If using the debug logger here it kill the typing in the `server_world_state_synchroniser` and jest tests. | ||
// console.log(`Function selector for ${signature} is ${selector}`); | ||
return selector; | ||
} | ||
@@ -104,0 +107,0 @@ |
@@ -99,4 +99,5 @@ import { Buffer } from 'buffer'; | ||
} | ||
// Is this a dictionary? | ||
if (obj.constructor === Object) { | ||
if (typeof obj === 'object') { | ||
const newObj: any = {}; | ||
@@ -123,2 +124,3 @@ for (const key of Object.keys(obj)) { | ||
} | ||
// Is this a Node buffer? | ||
@@ -140,2 +142,3 @@ if (obj instanceof Buffer) { | ||
} | ||
// Is this an array? | ||
@@ -145,16 +148,19 @@ if (Array.isArray(obj)) { | ||
} | ||
// Is this a dictionary? | ||
if (obj.constructor === Object) { | ||
const newObj: any = {}; | ||
for (const key of Object.keys(obj)) { | ||
newObj[key] = convertToJsonObj(cc, obj[key]); | ||
if (typeof obj === 'object') { | ||
// Is this a dictionary? | ||
if (isPlainObject(obj)) { | ||
const newObj: any = {}; | ||
for (const key of Object.keys(obj)) { | ||
newObj[key] = convertToJsonObj(cc, obj[key]); | ||
} | ||
return newObj; | ||
} else { | ||
// Throw if this is a non-primitive class that was not registered | ||
throw new Error(`Object ${obj.constructor.name} not registered for serialisation`); | ||
} | ||
return newObj; | ||
} | ||
// Throw if this is a non-primitive class that was not registered | ||
if (typeof obj === 'object' && !isPlainObject(obj)) { | ||
throw new Error(`Object ${obj.constructor.name} not registered for serialisation`); | ||
} | ||
// Leave alone, assume JSON primitive | ||
return obj; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1001211
16375