Comparing version 2.1.0 to 2.1.1
@@ -0,1 +1,8 @@ | ||
## [2.1.1](https://github.com/seanjameshan/starknet.js/compare/v2.1.0...v2.1.1) (2021-11-30) | ||
### Bug Fixes | ||
- correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1)) | ||
- make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f)) | ||
# [2.1.0](https://github.com/seanjameshan/starknet.js/compare/v2.0.1...v2.1.0) (2021-11-30) | ||
@@ -12,2 +19,9 @@ | ||
## [2.0.2](https://github.com/seanjameshan/starknet.js/compare/v2.0.1...v2.0.2) (2021-11-22) | ||
### Bug Fixes | ||
- correctly parse structs in Starknet return types ([5a4a318](https://github.com/seanjameshan/starknet.js/commit/5a4a318dad4c78fe84540ad92063fc1879317ac1)) | ||
- make Typescript compiler happy with constant types ([aedd895](https://github.com/seanjameshan/starknet.js/commit/aedd895a62e6018dd1d7330b004d54360007967f)) | ||
## [2.0.1](https://github.com/seanjameshan/starknet.js/compare/v2.0.0...v2.0.1) (2021-11-18) | ||
@@ -14,0 +28,0 @@ |
@@ -1,7 +0,7 @@ | ||
/// <reference types="bn.js" /> | ||
import BN from 'bn.js'; | ||
export { IS_BROWSER } from './utils/encode'; | ||
export declare const ZERO: import('bn.js'); | ||
export declare const ONE: import('bn.js'); | ||
export declare const TWO: import('bn.js'); | ||
export declare const MASK_250: import('bn.js'); | ||
export declare const ZERO: BN; | ||
export declare const ONE: BN; | ||
export declare const TWO: BN; | ||
export declare const MASK_250: BN; | ||
/** | ||
@@ -8,0 +8,0 @@ * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default |
import { Provider } from './provider'; | ||
import { Abi } from './types'; | ||
import { Abi, StructAbi } from './types'; | ||
import { BigNumberish } from './utils/number'; | ||
@@ -12,2 +12,5 @@ export declare type Args = { | ||
abi: Abi[]; | ||
structs: { | ||
[name: string]: StructAbi; | ||
}; | ||
provider: Provider; | ||
@@ -23,2 +26,3 @@ /** | ||
private validateMethodAndArgs; | ||
private parseResponseField; | ||
private parseResponse; | ||
@@ -25,0 +29,0 @@ invoke( |
@@ -241,2 +241,10 @@ 'use strict'; | ||
this.abi = abi; | ||
this.structs = abi | ||
.filter(function (abiEntry) { | ||
return abiEntry.type === 'struct'; | ||
}) | ||
.reduce(function (acc, abiEntry) { | ||
var _a; | ||
return __assign(__assign({}, acc), ((_a = {}), (_a[abiEntry.name] = abiEntry), _a)); | ||
}, {}); | ||
} | ||
@@ -254,5 +262,5 @@ Contract.prototype.connect = function (address) { | ||
.filter(function (abi) { | ||
if (abi.type !== 'function') return false; | ||
var isView = abi.stateMutability === 'view'; | ||
var isFunction = abi.type === 'function'; | ||
return isFunction && type === 'INVOKE' ? !isView : isView; | ||
return type === 'INVOKE' ? !isView : isView; | ||
}) | ||
@@ -268,3 +276,3 @@ .map(function (abi) { | ||
var methodAbi = this.abi.find(function (abi) { | ||
return abi.name === method; | ||
return abi.name === method && abi.type === 'function'; | ||
}); | ||
@@ -297,2 +305,21 @@ methodAbi.inputs.forEach(function (input) { | ||
}; | ||
Contract.prototype.parseResponseField = function (element, responseIterator) { | ||
var _this = this; | ||
var entries = []; | ||
if (['felt', 'felt*'].includes(element.type)) { | ||
return responseIterator.next().value; | ||
} | ||
if (element.type in this.structs) { | ||
entries = this.structs[element.type].members; | ||
} else if ('outputs' in element) { | ||
entries = element.outputs; | ||
} | ||
return entries.reduce(function (acc, member) { | ||
var _a; | ||
return __assign( | ||
__assign({}, acc), | ||
((_a = {}), (_a[member.name] = _this.parseResponseField(member, responseIterator)), _a) | ||
); | ||
}, {}); | ||
}; | ||
Contract.prototype.parseResponse = function (method, response) { | ||
@@ -302,6 +329,4 @@ var methodAbi = this.abi.find(function (abi) { | ||
}); | ||
return methodAbi.outputs.reduce(function (acc, output, i) { | ||
var _a; | ||
return __assign(__assign({}, acc), ((_a = {}), (_a[output.name] = response[i]), _a)); | ||
}, {}); | ||
var responseIterator = response.flat()[Symbol.iterator](); | ||
return this.parseResponseField(methodAbi, responseIterator); | ||
}; | ||
@@ -308,0 +333,0 @@ Contract.prototype.invoke = function (method, args, signature) { |
@@ -1,7 +0,7 @@ | ||
/// <reference types="bn.js" /> | ||
import BN from 'bn.js'; | ||
export { IS_BROWSER } from './utils/encode'; | ||
export declare const ZERO: import("bn.js"); | ||
export declare const ONE: import("bn.js"); | ||
export declare const TWO: import("bn.js"); | ||
export declare const MASK_250: import("bn.js"); | ||
export declare const ZERO: BN; | ||
export declare const ONE: BN; | ||
export declare const TWO: BN; | ||
export declare const MASK_250: BN; | ||
/** | ||
@@ -8,0 +8,0 @@ * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default |
import { Provider } from './provider'; | ||
import { Abi } from './types'; | ||
import { Abi, StructAbi } from './types'; | ||
import { BigNumberish } from './utils/number'; | ||
@@ -12,2 +12,5 @@ export declare type Args = { | ||
abi: Abi[]; | ||
structs: { | ||
[name: string]: StructAbi; | ||
}; | ||
provider: Provider; | ||
@@ -23,2 +26,3 @@ /** | ||
private validateMethodAndArgs; | ||
private parseResponseField; | ||
private parseResponse; | ||
@@ -25,0 +29,0 @@ invoke(method: string, args?: Args, signature?: [BigNumberish, BigNumberish]): Promise<import("./types").AddTransactionResponse>; |
@@ -122,2 +122,8 @@ "use strict"; | ||
this.abi = abi; | ||
this.structs = abi | ||
.filter(function (abiEntry) { return abiEntry.type === 'struct'; }) | ||
.reduce(function (acc, abiEntry) { | ||
var _a; | ||
return (__assign(__assign({}, acc), (_a = {}, _a[abiEntry.name] = abiEntry, _a))); | ||
}, {}); | ||
} | ||
@@ -133,5 +139,6 @@ Contract.prototype.connect = function (address) { | ||
.filter(function (abi) { | ||
if (abi.type !== 'function') | ||
return false; | ||
var isView = abi.stateMutability === 'view'; | ||
var isFunction = abi.type === 'function'; | ||
return isFunction && type === 'INVOKE' ? !isView : isView; | ||
return type === 'INVOKE' ? !isView : isView; | ||
}) | ||
@@ -141,3 +148,3 @@ .map(function (abi) { return abi.name; }); | ||
// ensure args match abi type | ||
var methodAbi = this.abi.find(function (abi) { return abi.name === method; }); | ||
var methodAbi = this.abi.find(function (abi) { return abi.name === method && abi.type === 'function'; }); | ||
methodAbi.inputs.forEach(function (input) { | ||
@@ -159,9 +166,24 @@ if (args[input.name] !== undefined) { | ||
}; | ||
Contract.prototype.parseResponse = function (method, response) { | ||
var methodAbi = this.abi.find(function (abi) { return abi.name === method; }); | ||
return methodAbi.outputs.reduce(function (acc, output, i) { | ||
Contract.prototype.parseResponseField = function (element, responseIterator) { | ||
var _this = this; | ||
var entries = []; | ||
if (['felt', 'felt*'].includes(element.type)) { | ||
return responseIterator.next().value; | ||
} | ||
if (element.type in this.structs) { | ||
entries = this.structs[element.type].members; | ||
} | ||
else if ('outputs' in element) { | ||
entries = element.outputs; | ||
} | ||
return entries.reduce(function (acc, member) { | ||
var _a; | ||
return __assign(__assign({}, acc), (_a = {}, _a[output.name] = response[i], _a)); | ||
return (__assign(__assign({}, acc), (_a = {}, _a[member.name] = _this.parseResponseField(member, responseIterator), _a))); | ||
}, {}); | ||
}; | ||
Contract.prototype.parseResponse = function (method, response) { | ||
var methodAbi = this.abi.find(function (abi) { return abi.name === method; }); | ||
var responseIterator = response.flat()[Symbol.iterator](); | ||
return this.parseResponseField(methodAbi, responseIterator); | ||
}; | ||
Contract.prototype.invoke = function (method, args, signature) { | ||
@@ -168,0 +190,0 @@ if (args === void 0) { args = {}; } |
@@ -14,15 +14,22 @@ import type { ec as EC } from 'elliptic'; | ||
export declare type CompressedProgram = string; | ||
export declare type Abi = { | ||
inputs: { | ||
name: string; | ||
type: 'felt' | 'felt*'; | ||
}[]; | ||
export declare type AbiEntry = { | ||
name: string; | ||
outputs: { | ||
name: string; | ||
type: 'felt' | 'felt*'; | ||
}[]; | ||
type: 'felt' | 'felt*' | string; | ||
}; | ||
export declare type FunctionAbi = { | ||
inputs: AbiEntry[]; | ||
name: string; | ||
outputs: AbiEntry[]; | ||
stateMutability?: 'view'; | ||
type: 'function'; | ||
}; | ||
export declare type StructAbi = { | ||
members: (AbiEntry & { | ||
offset: number; | ||
})[]; | ||
name: string; | ||
size: number; | ||
type: 'struct'; | ||
}; | ||
export declare type Abi = FunctionAbi | StructAbi; | ||
export declare type EntryPointsByType = object; | ||
@@ -29,0 +36,0 @@ export declare type Program = object; |
{ | ||
"name": "starknet", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "JavaScript library for StarkNet", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -5,3 +5,3 @@ import BN from 'bn.js'; | ||
import { Provider, defaultProvider } from './provider'; | ||
import { Abi } from './types'; | ||
import { Abi, AbiEntry, FunctionAbi, StructAbi } from './types'; | ||
import { BigNumberish, toBN } from './utils/number'; | ||
@@ -43,2 +43,4 @@ import { getSelectorFromName } from './utils/stark'; | ||
structs: { [name: string]: StructAbi }; | ||
provider: Provider; | ||
@@ -56,2 +58,11 @@ | ||
this.abi = abi; | ||
this.structs = abi | ||
.filter((abiEntry) => abiEntry.type === 'struct') | ||
.reduce( | ||
(acc, abiEntry) => ({ | ||
...acc, | ||
[abiEntry.name]: abiEntry, | ||
}), | ||
{} | ||
); | ||
} | ||
@@ -68,5 +79,5 @@ | ||
.filter((abi) => { | ||
if (abi.type !== 'function') return false; | ||
const isView = abi.stateMutability === 'view'; | ||
const isFunction = abi.type === 'function'; | ||
return isFunction && type === 'INVOKE' ? !isView : isView; | ||
return type === 'INVOKE' ? !isView : isView; | ||
}) | ||
@@ -80,3 +91,5 @@ .map((abi) => abi.name); | ||
// ensure args match abi type | ||
const methodAbi = this.abi.find((abi) => abi.name === method)!; | ||
const methodAbi = this.abi.find( | ||
(abi) => abi.name === method && abi.type === 'function' | ||
) as FunctionAbi; | ||
methodAbi.inputs.forEach((input) => { | ||
@@ -110,12 +123,30 @@ if (args[input.name] !== undefined) { | ||
private parseResponse(method: string, response: (string | string[])[]): Args { | ||
const methodAbi = this.abi.find((abi) => abi.name === method)!; | ||
return methodAbi.outputs.reduce((acc, output, i) => { | ||
return { | ||
private parseResponseField( | ||
element: AbiEntry | FunctionAbi, | ||
responseIterator: Iterator<string> | ||
): Args { | ||
let entries: AbiEntry[] = []; | ||
if (['felt', 'felt*'].includes(element.type)) { | ||
return responseIterator.next().value; | ||
} | ||
if (element.type in this.structs) { | ||
entries = this.structs[element.type].members; | ||
} else if ('outputs' in element) { | ||
entries = element.outputs; | ||
} | ||
return entries.reduce( | ||
(acc, member) => ({ | ||
...acc, | ||
[output.name]: response[i], | ||
}; | ||
}, {} as Args); | ||
[member.name]: this.parseResponseField(member, responseIterator), | ||
}), | ||
{} | ||
); | ||
} | ||
private parseResponse(method: string, response: string[]): Args { | ||
const methodAbi = this.abi.find((abi) => abi.name === method) as FunctionAbi; | ||
const responseIterator = response.flat()[Symbol.iterator](); | ||
return this.parseResponseField(methodAbi, responseIterator); | ||
} | ||
public invoke(method: string, args: Args = {}, signature?: [BigNumberish, BigNumberish]) { | ||
@@ -122,0 +153,0 @@ // ensure contract is connected |
@@ -19,9 +19,21 @@ import type { ec as EC } from 'elliptic'; | ||
export type Abi = { | ||
inputs: { name: string; type: 'felt' | 'felt*' }[]; | ||
export type AbiEntry = { name: string; type: 'felt' | 'felt*' | string }; | ||
export type FunctionAbi = { | ||
inputs: AbiEntry[]; | ||
name: string; | ||
outputs: { name: string; type: 'felt' | 'felt*' }[]; | ||
outputs: AbiEntry[]; | ||
stateMutability?: 'view'; | ||
type: 'function'; | ||
}; | ||
export type StructAbi = { | ||
members: (AbiEntry & { offset: number })[]; | ||
name: string; | ||
size: number; | ||
type: 'struct'; | ||
}; | ||
export type Abi = FunctionAbi | StructAbi; | ||
export type EntryPointsByType = object; | ||
@@ -28,0 +40,0 @@ export type Program = object; |
@@ -20,15 +20,22 @@ import type { ec as EC } from 'elliptic'; | ||
export declare type CompressedProgram = string; | ||
export declare type Abi = { | ||
inputs: { | ||
name: string; | ||
type: 'felt' | 'felt*'; | ||
}[]; | ||
export declare type AbiEntry = { | ||
name: string; | ||
outputs: { | ||
name: string; | ||
type: 'felt' | 'felt*'; | ||
}[]; | ||
type: 'felt' | 'felt*' | string; | ||
}; | ||
export declare type FunctionAbi = { | ||
inputs: AbiEntry[]; | ||
name: string; | ||
outputs: AbiEntry[]; | ||
stateMutability?: 'view'; | ||
type: 'function'; | ||
}; | ||
export declare type StructAbi = { | ||
members: (AbiEntry & { | ||
offset: number; | ||
})[]; | ||
name: string; | ||
size: number; | ||
type: 'struct'; | ||
}; | ||
export declare type Abi = FunctionAbi | StructAbi; | ||
export declare type EntryPointsByType = object; | ||
@@ -35,0 +42,0 @@ export declare type Program = object; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5355532
139096