Comparing version 2.3.0 to 2.3.1
@@ -0,1 +1,10 @@ | ||
## [2.3.1](https://github.com/seanjameshan/starknet.js/compare/v2.3.0...v2.3.1) (2021-12-01) | ||
### Bug Fixes | ||
- allow structs in calldata ([fd2bdc0](https://github.com/seanjameshan/starknet.js/commit/fd2bdc0a1756544e4162fa5baaa7d3aec6f97bee)) | ||
- struct compiling ([84617ae](https://github.com/seanjameshan/starknet.js/commit/84617aefe1218f421ca446b2a3c9959252d326e6)) | ||
- struct data ([313dff5](https://github.com/seanjameshan/starknet.js/commit/313dff57f54050747c65b32b3378762c349d9c8c)) | ||
- uint256 type ([2e05902](https://github.com/seanjameshan/starknet.js/commit/2e05902268f76bda2ae9b4e75782fa78876c2f00)) | ||
# [2.3.0](https://github.com/seanjameshan/starknet.js/compare/v2.2.0...v2.3.0) (2021-12-01) | ||
@@ -2,0 +11,0 @@ |
@@ -5,3 +5,9 @@ import { Provider } from './provider'; | ||
export declare type Args = { | ||
[inputName: string]: string | string[]; | ||
[inputName: string]: | ||
| string | ||
| string[] | ||
| { | ||
type: 'struct'; | ||
[k: string]: BigNumberish; | ||
}; | ||
}; | ||
@@ -8,0 +14,0 @@ export declare type Calldata = string[]; |
@@ -219,2 +219,14 @@ 'use strict'; | ||
); | ||
if (typeof value === 'object' && 'type' in value) | ||
return Object.entries(value) | ||
.filter(function (_a) { | ||
var _b = __read(_a, 1), | ||
k = _b[0]; | ||
return k !== 'type'; | ||
}) | ||
.map(function (_a) { | ||
var _b = __read(_a, 2), | ||
v = _b[1]; | ||
return (0, number_1.toBN)(v).toString(); | ||
}); | ||
return (0, number_1.toBN)(value).toString(); | ||
@@ -278,18 +290,24 @@ }); | ||
methodAbi.inputs.forEach(function (input) { | ||
if (args[input.name] !== undefined) { | ||
var arg = args[input.name]; | ||
if (arg !== undefined) { | ||
if (input.type === 'felt') { | ||
(0, minimalistic_assert_1.default)( | ||
typeof args[input.name] === 'string', | ||
typeof arg === 'string', | ||
'arg ' + input.name + ' should be a felt (string)' | ||
); | ||
(0, minimalistic_assert_1.default)( | ||
isFelt(args[input.name]), | ||
isFelt(arg), | ||
'arg ' + input.name + ' should be decimal or hexadecimal' | ||
); | ||
} else if (typeof arg === 'object' && 'type' in arg) { | ||
(0, minimalistic_assert_1.default)( | ||
arg.type === 'struct', | ||
'arg ' + input.name + ' should be a struct' | ||
); | ||
} else { | ||
(0, minimalistic_assert_1.default)( | ||
Array.isArray(args[input.name]), | ||
Array.isArray(arg), | ||
'arg ' + input.name + ' should be a felt* (string[])' | ||
); | ||
args[input.name].forEach(function (felt, i) { | ||
arg.forEach(function (felt, i) { | ||
(0, | ||
@@ -296,0 +314,0 @@ minimalistic_assert_1.default)(typeof felt === 'string', 'arg ' + input.name + '[' + i + '] should be a felt (string) as part of a felt* (string[])'); |
@@ -5,3 +5,6 @@ import { Provider } from './provider'; | ||
export declare type Args = { | ||
[inputName: string]: string | string[]; | ||
[inputName: string]: string | string[] | { | ||
type: 'struct'; | ||
[k: string]: BigNumberish; | ||
}; | ||
}; | ||
@@ -8,0 +11,0 @@ export declare type Calldata = string[]; |
@@ -104,2 +104,12 @@ "use strict"; | ||
return __spreadArray([(0, number_1.toBN)(value.length).toString()], __read(value.map(function (x) { return (0, number_1.toBN)(x).toString(); })), false); | ||
if (typeof value === 'object' && 'type' in value) | ||
return Object.entries(value) | ||
.filter(function (_a) { | ||
var _b = __read(_a, 1), k = _b[0]; | ||
return k !== 'type'; | ||
}) | ||
.map(function (_a) { | ||
var _b = __read(_a, 2), v = _b[1]; | ||
return (0, number_1.toBN)(v).toString(); | ||
}); | ||
return (0, number_1.toBN)(value).toString(); | ||
@@ -149,10 +159,14 @@ }); | ||
methodAbi.inputs.forEach(function (input) { | ||
if (args[input.name] !== undefined) { | ||
var arg = args[input.name]; | ||
if (arg !== undefined) { | ||
if (input.type === 'felt') { | ||
(0, minimalistic_assert_1.default)(typeof args[input.name] === 'string', "arg " + input.name + " should be a felt (string)"); | ||
(0, minimalistic_assert_1.default)(isFelt(args[input.name]), "arg " + input.name + " should be decimal or hexadecimal"); | ||
(0, minimalistic_assert_1.default)(typeof arg === 'string', "arg " + input.name + " should be a felt (string)"); | ||
(0, minimalistic_assert_1.default)(isFelt(arg), "arg " + input.name + " should be decimal or hexadecimal"); | ||
} | ||
else if (typeof arg === 'object' && 'type' in arg) { | ||
(0, minimalistic_assert_1.default)(arg.type === 'struct', "arg " + input.name + " should be a struct"); | ||
} | ||
else { | ||
(0, minimalistic_assert_1.default)(Array.isArray(args[input.name]), "arg " + input.name + " should be a felt* (string[])"); | ||
args[input.name].forEach(function (felt, i) { | ||
(0, minimalistic_assert_1.default)(Array.isArray(arg), "arg " + input.name + " should be a felt* (string[])"); | ||
arg.forEach(function (felt, i) { | ||
(0, minimalistic_assert_1.default)(typeof felt === 'string', "arg " + input.name + "[" + i + "] should be a felt (string) as part of a felt* (string[])"); | ||
@@ -159,0 +173,0 @@ (0, minimalistic_assert_1.default)(isFelt(felt), "arg " + input.name + "[" + i + "] should be decimal or hexadecimal as part of a felt* (string[])"); |
@@ -22,4 +22,1 @@ import { CompressedProgram, Program } from '../types'; | ||
export declare function formatSignature(sig?: [BigNumberish, BigNumberish]): [string, string] | []; | ||
export declare function compileStructToCalldata<S extends { | ||
[k: string]: string; | ||
}>(struct: S): string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.compileStructToCalldata = exports.formatSignature = exports.makeAddress = exports.randomAddress = exports.getSelectorFromName = exports.compressProgram = void 0; | ||
exports.formatSignature = exports.makeAddress = exports.randomAddress = exports.getSelectorFromName = exports.compressProgram = void 0; | ||
var pako_1 = require("pako"); | ||
@@ -55,5 +55,1 @@ var ellipticCurve_1 = require("./ellipticCurve"); | ||
exports.formatSignature = formatSignature; | ||
function compileStructToCalldata(struct) { | ||
return Object.values(struct); | ||
} | ||
exports.compileStructToCalldata = compileStructToCalldata; |
{ | ||
"name": "starknet", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "JavaScript library for StarkNet", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -9,3 +9,5 @@ import BN from 'bn.js'; | ||
export type Args = { [inputName: string]: string | string[] }; | ||
export type Args = { | ||
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish }; | ||
}; | ||
export type Calldata = string[]; | ||
@@ -34,2 +36,6 @@ | ||
return [toBN(value.length).toString(), ...value.map((x) => toBN(x).toString())]; | ||
if (typeof value === 'object' && 'type' in value) | ||
return Object.entries(value) | ||
.filter(([k]) => k !== 'type') | ||
.map(([, v]) => toBN(v).toString()); | ||
return toBN(value).toString(); | ||
@@ -93,15 +99,12 @@ }); | ||
methodAbi.inputs.forEach((input) => { | ||
if (args[input.name] !== undefined) { | ||
const arg = args[input.name]; | ||
if (arg !== undefined) { | ||
if (input.type === 'felt') { | ||
assert( | ||
typeof args[input.name] === 'string', | ||
`arg ${input.name} should be a felt (string)` | ||
); | ||
assert( | ||
isFelt(args[input.name] as string), | ||
`arg ${input.name} should be decimal or hexadecimal` | ||
); | ||
assert(typeof arg === 'string', `arg ${input.name} should be a felt (string)`); | ||
assert(isFelt(arg as string), `arg ${input.name} should be decimal or hexadecimal`); | ||
} else if (typeof arg === 'object' && 'type' in arg) { | ||
assert(arg.type === 'struct', `arg ${input.name} should be a struct`); | ||
} else { | ||
assert(Array.isArray(args[input.name]), `arg ${input.name} should be a felt* (string[])`); | ||
(args[input.name] as string[]).forEach((felt, i) => { | ||
assert(Array.isArray(arg), `arg ${input.name} should be a felt* (string[])`); | ||
(arg as string[]).forEach((felt, i) => { | ||
assert( | ||
@@ -108,0 +111,0 @@ typeof felt === 'string', |
@@ -52,5 +52,1 @@ import { gzip } from 'pako'; | ||
} | ||
export function compileStructToCalldata<S extends { [k: string]: string }>(struct: S): string[] { | ||
return Object.values(struct); | ||
} |
@@ -22,6 +22,1 @@ import { CompressedProgram, Program } from '../types'; | ||
export declare function formatSignature(sig?: [BigNumberish, BigNumberish]): [string, string] | []; | ||
export declare function compileStructToCalldata< | ||
S extends { | ||
[k: string]: string; | ||
} | ||
>(struct: S): string[]; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.compileStructToCalldata = | ||
exports.formatSignature = | ||
exports.formatSignature = | ||
exports.makeAddress = | ||
@@ -66,5 +65,1 @@ exports.randomAddress = | ||
exports.formatSignature = formatSignature; | ||
function compileStructToCalldata(struct) { | ||
return Object.values(struct); | ||
} | ||
exports.compileStructToCalldata = compileStructToCalldata; |
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
5371256
139431