starknet 0.1.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +6 -0
- package/.commitlintrc +12 -0
- package/.eslintignore +2 -0
- package/.eslintrc +20 -0
- package/.github/workflows/pr.yml +23 -0
- package/.github/workflows/release.yml +40 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/{.prettierrc.json → .prettierrc} +0 -1
- package/.releaserc +28 -0
- package/CHANGELOG.md +49 -0
- package/CONTRIBUTING.md +52 -0
- package/README.md +39 -11
- package/__mocks__/ArgentAccount.json +92620 -0
- package/__tests__/__snapshots__/utils.browser.test.ts.snap +5 -0
- package/__tests__/__snapshots__/utils.test.ts.snap +5 -0
- package/__tests__/index.test.ts +49 -4
- package/__tests__/utils.browser.test.ts +30 -0
- package/__tests__/utils.test.ts +35 -0
- package/constants.d.ts +3 -0
- package/constants.js +9 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +6 -0
- package/dist/index.d.ts +23 -9
- package/dist/index.js +51 -5
- package/dist/types.d.ts +89 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.js +44 -0
- package/docs/README.md +235 -0
- package/index.d.ts +115 -0
- package/index.js +261 -0
- package/package.json +29 -5
- package/src/constants.ts +3 -0
- package/src/index.ts +67 -21
- package/src/types.ts +95 -0
- package/src/utils.ts +44 -0
- package/tsconfig.eslint.json +4 -0
- package/tsconfig.json +15 -13
- package/types.d.ts +94 -0
- package/types.js +2 -0
- package/utils.d.ts +29 -0
- package/utils.js +62 -0
- package/.eslintrc.json +0 -26
- package/babel.config.js +0 -3
- package/dist/__tests__/index.test.d.ts +0 -1
- package/dist/__tests__/index.test.js +0 -49
- package/docs/Home.md +0 -220
- package/docs/_Sidebar.md +0 -3
package/__tests__/index.test.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import starknet, {
|
|
3
|
+
CompiledContract,
|
|
4
|
+
compressProgram,
|
|
5
|
+
randomAddress,
|
|
6
|
+
makeAddress,
|
|
7
|
+
JsonParser,
|
|
8
|
+
} from '..';
|
|
9
|
+
|
|
10
|
+
const compiledArgentAccount = JsonParser.parse(
|
|
11
|
+
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
|
|
12
|
+
);
|
|
2
13
|
|
|
3
14
|
describe('starknet endpoints', () => {
|
|
4
15
|
describe('feeder gateway endpoints', () => {
|
|
@@ -29,10 +40,44 @@ describe('starknet endpoints', () => {
|
|
|
29
40
|
test('getTransaction()', () => {
|
|
30
41
|
return expect(starknet.getTransaction(286136)).resolves.not.toThrow();
|
|
31
42
|
});
|
|
32
|
-
xtest('addTransaction()', () => {});
|
|
33
43
|
});
|
|
34
44
|
|
|
35
|
-
describe('
|
|
36
|
-
|
|
45
|
+
describe('addTransaction()', () => {
|
|
46
|
+
test('type: "DEPLOY"', async () => {
|
|
47
|
+
const inputContract = compiledArgentAccount as unknown as CompiledContract;
|
|
48
|
+
|
|
49
|
+
const contractDefinition = {
|
|
50
|
+
...inputContract,
|
|
51
|
+
program: compressProgram(inputContract.program),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const response = await starknet.addTransaction({
|
|
55
|
+
type: 'DEPLOY',
|
|
56
|
+
contract_address: randomAddress(),
|
|
57
|
+
contract_definition: contractDefinition,
|
|
58
|
+
});
|
|
59
|
+
expect(response.code).toBe('TRANSACTION_RECEIVED');
|
|
60
|
+
expect(response.tx_id).toBeGreaterThan(0);
|
|
61
|
+
|
|
62
|
+
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
console.log('txId:', response.tx_id);
|
|
65
|
+
});
|
|
66
|
+
xtest('type: "INVOKE_FUNCTION"', () => {});
|
|
67
|
+
|
|
68
|
+
test('deployContract()', async () => {
|
|
69
|
+
const inputContract = compiledArgentAccount as unknown as CompiledContract;
|
|
70
|
+
|
|
71
|
+
const response = await starknet.deployContract(
|
|
72
|
+
inputContract,
|
|
73
|
+
makeAddress('0x20b5B1b8aFd65F1FCB755a449000cFC4aBCA0D40')
|
|
74
|
+
);
|
|
75
|
+
expect(response.code).toBe('TRANSACTION_RECEIVED');
|
|
76
|
+
expect(response.tx_id).toBeGreaterThan(0);
|
|
77
|
+
|
|
78
|
+
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
|
|
79
|
+
// eslint-disable-next-line no-console
|
|
80
|
+
console.log('txId:', response.tx_id);
|
|
81
|
+
});
|
|
37
82
|
});
|
|
38
83
|
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import { compressProgram, isBrowser, JsonParser } from '..';
|
|
7
|
+
|
|
8
|
+
const compiledArgentAccount = JsonParser.parse(
|
|
9
|
+
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
test('isBrowser', () => {
|
|
13
|
+
expect(isBrowser).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
describe('compressProgram()', () => {
|
|
16
|
+
test('compresses a contract program', () => {
|
|
17
|
+
const inputContract = compiledArgentAccount as any;
|
|
18
|
+
|
|
19
|
+
const compressed = compressProgram(inputContract.program);
|
|
20
|
+
|
|
21
|
+
expect(compressed).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
test('works with strings', () => {
|
|
24
|
+
const inputProgram = JsonParser.stringify(compiledArgentAccount.program);
|
|
25
|
+
|
|
26
|
+
const compressed = compressProgram(inputProgram);
|
|
27
|
+
|
|
28
|
+
expect(compressed).toMatchSnapshot();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { compressProgram, makeAddress, isBrowser, JsonParser } from '..';
|
|
3
|
+
|
|
4
|
+
const compiledArgentAccount = JsonParser.parse(
|
|
5
|
+
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
test('isNode', () => {
|
|
9
|
+
expect(isBrowser).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
describe('compressProgram()', () => {
|
|
12
|
+
test('compresses a contract program', () => {
|
|
13
|
+
const inputProgram = compiledArgentAccount.program;
|
|
14
|
+
|
|
15
|
+
const compressed = compressProgram(inputProgram);
|
|
16
|
+
|
|
17
|
+
expect(compressed).toMatchSnapshot();
|
|
18
|
+
});
|
|
19
|
+
test('works with strings', () => {
|
|
20
|
+
const inputProgram = JsonParser.stringify(compiledArgentAccount.program);
|
|
21
|
+
|
|
22
|
+
const compressed = compressProgram(inputProgram);
|
|
23
|
+
|
|
24
|
+
expect(compressed).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('makeAddress()', () => {
|
|
28
|
+
test('test on eth address', () => {
|
|
29
|
+
const ethAddress = '0xdFD0F27FCe99b50909de0bDD328Aed6eAbe76BC5';
|
|
30
|
+
|
|
31
|
+
const starkAddress = makeAddress(ethAddress);
|
|
32
|
+
|
|
33
|
+
expect(starkAddress).toBe('0xdfd0f27fce99b50909de0bdd328aed6eabe76bc5');
|
|
34
|
+
});
|
|
35
|
+
});
|
package/constants.d.ts
ADDED
package/constants.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.CONTRACT_ADDRESS_UPPER_BOUND =
|
|
4
|
+
exports.CONTRACT_ADDRESS_LOWER_BOUND =
|
|
5
|
+
exports.CONTRACT_ADDRESS_BITS =
|
|
6
|
+
void 0;
|
|
7
|
+
exports.CONTRACT_ADDRESS_BITS = 251;
|
|
8
|
+
exports.CONTRACT_ADDRESS_LOWER_BOUND = 1;
|
|
9
|
+
exports.CONTRACT_ADDRESS_UPPER_BOUND = Math.pow(2, exports.CONTRACT_ADDRESS_BITS);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONTRACT_ADDRESS_UPPER_BOUND = exports.CONTRACT_ADDRESS_LOWER_BOUND = exports.CONTRACT_ADDRESS_BITS = void 0;
|
|
4
|
+
exports.CONTRACT_ADDRESS_BITS = 251;
|
|
5
|
+
exports.CONTRACT_ADDRESS_LOWER_BOUND = 1;
|
|
6
|
+
exports.CONTRACT_ADDRESS_UPPER_BOUND = Math.pow(2, exports.CONTRACT_ADDRESS_BITS);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { compressProgram } from './utils';
|
|
2
|
+
import type { GetBlockResponse, GetCode, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Transaction, AddTransactionResponse, CompiledContract } from './types';
|
|
1
3
|
/**
|
|
2
4
|
* Gets the smart contract address on the goerli testnet.
|
|
3
5
|
*
|
|
4
|
-
* https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15
|
|
5
|
-
* @returns starknet smart contract
|
|
6
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
|
|
7
|
+
* @returns starknet smart contract addresses
|
|
6
8
|
*/
|
|
7
|
-
export declare function getContractAddresses(): Promise<
|
|
9
|
+
export declare function getContractAddresses(): Promise<GetContractAddressesResponse>;
|
|
8
10
|
/**
|
|
9
11
|
* Calls a function on the StarkNet contract.
|
|
10
12
|
*
|
|
@@ -23,7 +25,7 @@ export declare function callContract(invokeTx: object, blockId: number): Promise
|
|
|
23
25
|
* @param blockId
|
|
24
26
|
* @returns the block object { block_id, previous_block_id, state_root, status, timestamp, transaction_receipts, transactions }
|
|
25
27
|
*/
|
|
26
|
-
export declare function getBlock(blockId: number): Promise<
|
|
28
|
+
export declare function getBlock(blockId: number): Promise<GetBlockResponse>;
|
|
27
29
|
/**
|
|
28
30
|
* Gets the code of the deployed contract.
|
|
29
31
|
*
|
|
@@ -31,9 +33,9 @@ export declare function getBlock(blockId: number): Promise<object>;
|
|
|
31
33
|
*
|
|
32
34
|
* @param contractAddress
|
|
33
35
|
* @param blockId
|
|
34
|
-
* @returns ABI of compiled contract
|
|
36
|
+
* @returns Bytecode and ABI of compiled contract
|
|
35
37
|
*/
|
|
36
|
-
export declare function getCode(contractAddress: string, blockId: number): Promise<
|
|
38
|
+
export declare function getCode(contractAddress: string, blockId: number): Promise<GetCode>;
|
|
37
39
|
/**
|
|
38
40
|
* Gets the contract's storage variable at a specific key.
|
|
39
41
|
*
|
|
@@ -53,7 +55,7 @@ export declare function getStorageAt(contractAddress: string, key: number, block
|
|
|
53
55
|
* @param txId
|
|
54
56
|
* @returns the transaction status object { block_id, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
|
|
55
57
|
*/
|
|
56
|
-
export declare function getTransactionStatus(txId: number): Promise<
|
|
58
|
+
export declare function getTransactionStatus(txId: number): Promise<GetTransactionStatusResponse>;
|
|
57
59
|
/**
|
|
58
60
|
* Gets the transaction information from a tx id.
|
|
59
61
|
*
|
|
@@ -62,7 +64,7 @@ export declare function getTransactionStatus(txId: number): Promise<object>;
|
|
|
62
64
|
* @param txId
|
|
63
65
|
* @returns the transacton object { transaction_id, status, transaction, block_id?, block_number?, transaction_index?, transaction_failure_reason? }
|
|
64
66
|
*/
|
|
65
|
-
export declare function getTransaction(txId: number): Promise<
|
|
67
|
+
export declare function getTransaction(txId: number): Promise<GetTransactionResponse>;
|
|
66
68
|
/**
|
|
67
69
|
* Invoke a function on the starknet contract
|
|
68
70
|
*
|
|
@@ -71,7 +73,17 @@ export declare function getTransaction(txId: number): Promise<object>;
|
|
|
71
73
|
* @param tx - transaction to be invoked (WIP)
|
|
72
74
|
* @returns a confirmation of invoking a function on the starknet contract
|
|
73
75
|
*/
|
|
74
|
-
export declare function addTransaction(tx:
|
|
76
|
+
export declare function addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* Deploys a given compiled contract (json) to starknet
|
|
79
|
+
*
|
|
80
|
+
* @param contract - a json object containing the compiled contract
|
|
81
|
+
* @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
|
|
82
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
83
|
+
*/
|
|
84
|
+
export declare function deployContract(contract: CompiledContract | string, address?: string): Promise<AddTransactionResponse>;
|
|
85
|
+
export * from './utils';
|
|
86
|
+
export * from './types';
|
|
75
87
|
declare const _default: {
|
|
76
88
|
getContractAddresses: typeof getContractAddresses;
|
|
77
89
|
callContract: typeof callContract;
|
|
@@ -81,5 +93,7 @@ declare const _default: {
|
|
|
81
93
|
getTransactionStatus: typeof getTransactionStatus;
|
|
82
94
|
getTransaction: typeof getTransaction;
|
|
83
95
|
addTransaction: typeof addTransaction;
|
|
96
|
+
compressProgram: typeof compressProgram;
|
|
97
|
+
deployContract: typeof deployContract;
|
|
84
98
|
};
|
|
85
99
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
+
};
|
|
2
23
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
25
|
};
|
|
5
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.addTransaction = exports.getTransaction = exports.getTransactionStatus = exports.getStorageAt = exports.getCode = exports.getBlock = exports.callContract = exports.getContractAddresses = void 0;
|
|
27
|
+
exports.deployContract = exports.addTransaction = exports.getTransaction = exports.getTransactionStatus = exports.getStorageAt = exports.getCode = exports.getBlock = exports.callContract = exports.getContractAddresses = void 0;
|
|
7
28
|
var axios_1 = __importDefault(require("axios"));
|
|
8
|
-
var
|
|
29
|
+
var utils_1 = require("./utils");
|
|
30
|
+
var API_URL = 'https://alpha2.starknet.io';
|
|
9
31
|
var FEEDER_GATEWAY_URL = API_URL + "/feeder_gateway";
|
|
10
32
|
var GATEWAY_URL = API_URL + "/gateway";
|
|
11
33
|
/**
|
|
12
34
|
* Gets the smart contract address on the goerli testnet.
|
|
13
35
|
*
|
|
14
|
-
* https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15
|
|
15
|
-
* @returns starknet smart contract
|
|
36
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
|
|
37
|
+
* @returns starknet smart contract addresses
|
|
16
38
|
*/
|
|
17
39
|
function getContractAddresses() {
|
|
18
40
|
return new Promise(function (resolve, reject) {
|
|
@@ -25,6 +47,7 @@ function getContractAddresses() {
|
|
|
25
47
|
});
|
|
26
48
|
}
|
|
27
49
|
exports.getContractAddresses = getContractAddresses;
|
|
50
|
+
// TODO: add proper type
|
|
28
51
|
/**
|
|
29
52
|
* Calls a function on the StarkNet contract.
|
|
30
53
|
*
|
|
@@ -71,7 +94,7 @@ exports.getBlock = getBlock;
|
|
|
71
94
|
*
|
|
72
95
|
* @param contractAddress
|
|
73
96
|
* @param blockId
|
|
74
|
-
* @returns ABI of compiled contract
|
|
97
|
+
* @returns Bytecode and ABI of compiled contract
|
|
75
98
|
*/
|
|
76
99
|
function getCode(contractAddress, blockId) {
|
|
77
100
|
return new Promise(function (resolve, reject) {
|
|
@@ -84,6 +107,7 @@ function getCode(contractAddress, blockId) {
|
|
|
84
107
|
});
|
|
85
108
|
}
|
|
86
109
|
exports.getCode = getCode;
|
|
110
|
+
// TODO: add proper type
|
|
87
111
|
/**
|
|
88
112
|
* Gets the contract's storage variable at a specific key.
|
|
89
113
|
*
|
|
@@ -162,6 +186,26 @@ function addTransaction(tx) {
|
|
|
162
186
|
});
|
|
163
187
|
}
|
|
164
188
|
exports.addTransaction = addTransaction;
|
|
189
|
+
/**
|
|
190
|
+
* Deploys a given compiled contract (json) to starknet
|
|
191
|
+
*
|
|
192
|
+
* @param contract - a json object containing the compiled contract
|
|
193
|
+
* @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
|
|
194
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
195
|
+
*/
|
|
196
|
+
function deployContract(contract, address) {
|
|
197
|
+
if (address === void 0) { address = (0, utils_1.randomAddress)(); }
|
|
198
|
+
var parsedContract = typeof contract === 'string' ? utils_1.JsonParser.parse(contract) : contract;
|
|
199
|
+
var contractDefinition = __assign(__assign({}, parsedContract), { program: (0, utils_1.compressProgram)(parsedContract.program) });
|
|
200
|
+
return addTransaction({
|
|
201
|
+
type: 'DEPLOY',
|
|
202
|
+
contract_address: address,
|
|
203
|
+
contract_definition: contractDefinition,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
exports.deployContract = deployContract;
|
|
207
|
+
__exportStar(require("./utils"), exports);
|
|
208
|
+
__exportStar(require("./types"), exports);
|
|
165
209
|
exports.default = {
|
|
166
210
|
getContractAddresses: getContractAddresses,
|
|
167
211
|
callContract: callContract,
|
|
@@ -171,4 +215,6 @@ exports.default = {
|
|
|
171
215
|
getTransactionStatus: getTransactionStatus,
|
|
172
216
|
getTransaction: getTransaction,
|
|
173
217
|
addTransaction: addTransaction,
|
|
218
|
+
compressProgram: utils_1.compressProgram,
|
|
219
|
+
deployContract: deployContract,
|
|
174
220
|
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export interface GetContractAddressesResponse {
|
|
2
|
+
Starknet: string;
|
|
3
|
+
GpsStatementVerifier: string;
|
|
4
|
+
}
|
|
5
|
+
export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'REJECTED' | 'ACCEPTED_ONCHAIN';
|
|
6
|
+
export declare type TxStatus = 'TRANSACTION_RECEIVED';
|
|
7
|
+
export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
|
|
8
|
+
export declare type EntryPointType = 'EXTERNAL';
|
|
9
|
+
export declare type CompressedProgram = string;
|
|
10
|
+
export interface Abi {
|
|
11
|
+
inputs: {
|
|
12
|
+
name: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}[];
|
|
15
|
+
name: string;
|
|
16
|
+
outputs: {
|
|
17
|
+
name: string;
|
|
18
|
+
type: string;
|
|
19
|
+
}[];
|
|
20
|
+
type: string;
|
|
21
|
+
}
|
|
22
|
+
export declare type EntryPointsByType = object;
|
|
23
|
+
export declare type Program = object;
|
|
24
|
+
export interface CompiledContract {
|
|
25
|
+
abi: Abi;
|
|
26
|
+
entry_points_by_type: EntryPointsByType;
|
|
27
|
+
program: Program;
|
|
28
|
+
}
|
|
29
|
+
export interface CompressedCompiledContract extends Omit<CompiledContract, 'program'> {
|
|
30
|
+
program: CompressedProgram;
|
|
31
|
+
}
|
|
32
|
+
export interface DeployTransaction {
|
|
33
|
+
type: 'DEPLOY';
|
|
34
|
+
contract_definition: CompressedCompiledContract;
|
|
35
|
+
contract_address: string;
|
|
36
|
+
}
|
|
37
|
+
export interface InvokeFunctionTransaction {
|
|
38
|
+
type: 'INVOKE_FUNCTION';
|
|
39
|
+
contract_address: string;
|
|
40
|
+
entry_point_type?: EntryPointType;
|
|
41
|
+
entry_point_selector?: string;
|
|
42
|
+
calldata?: string[];
|
|
43
|
+
}
|
|
44
|
+
export declare type Transaction = DeployTransaction | InvokeFunctionTransaction;
|
|
45
|
+
export interface GetBlockResponse {
|
|
46
|
+
sequence_number: number;
|
|
47
|
+
state_root: string;
|
|
48
|
+
block_id: number;
|
|
49
|
+
transactions: {
|
|
50
|
+
[txid: string]: Transaction;
|
|
51
|
+
};
|
|
52
|
+
timestamp: number;
|
|
53
|
+
transaction_receipts: {
|
|
54
|
+
[txid: string]: {
|
|
55
|
+
block_id: number;
|
|
56
|
+
transaction_id: number;
|
|
57
|
+
l2_to_l1_messages: {
|
|
58
|
+
to_address: string;
|
|
59
|
+
payload: string[];
|
|
60
|
+
from_address: string;
|
|
61
|
+
}[];
|
|
62
|
+
block_number: number;
|
|
63
|
+
status: Status;
|
|
64
|
+
transaction_index: number;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
previous_block_id: number;
|
|
68
|
+
status: Status;
|
|
69
|
+
}
|
|
70
|
+
export interface GetCode {
|
|
71
|
+
bytecode: string[];
|
|
72
|
+
abi: Abi[];
|
|
73
|
+
}
|
|
74
|
+
export interface GetTransactionStatusResponse {
|
|
75
|
+
tx_status: Status;
|
|
76
|
+
block_id: number;
|
|
77
|
+
}
|
|
78
|
+
export interface GetTransactionResponse {
|
|
79
|
+
transaction_index: number;
|
|
80
|
+
transaction: Transaction;
|
|
81
|
+
block_id: number;
|
|
82
|
+
block_number: number;
|
|
83
|
+
status: Status;
|
|
84
|
+
transaction_id: number;
|
|
85
|
+
}
|
|
86
|
+
export interface AddTransactionResponse {
|
|
87
|
+
code: TxStatus;
|
|
88
|
+
tx_id: number;
|
|
89
|
+
}
|
package/dist/types.js
ADDED
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CompressedProgram, Program } from './types';
|
|
2
|
+
export declare const isBrowser: boolean;
|
|
3
|
+
export declare const btoaUniversal: (b: ArrayBuffer) => string;
|
|
4
|
+
export declare function randomIntFromInterval(min: number, max: number): number;
|
|
5
|
+
export declare function randomAddress(): string;
|
|
6
|
+
export declare function makeAddress(input: string): string;
|
|
7
|
+
export declare const JsonParser: {
|
|
8
|
+
parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any;
|
|
9
|
+
stringify: {
|
|
10
|
+
(value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
|
|
11
|
+
(value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Function to compress compiled cairo program
|
|
16
|
+
*
|
|
17
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/gateway/transaction.py#L54-L58)
|
|
18
|
+
* @param jsonProgram - json file representing the compiled cairo program
|
|
19
|
+
* @returns Compressed cairo program
|
|
20
|
+
*/
|
|
21
|
+
export declare function compressProgram(jsonProgram: Program | string): CompressedProgram;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.compressProgram = exports.JsonParser = exports.makeAddress = exports.randomAddress = exports.randomIntFromInterval = exports.btoaUniversal = exports.isBrowser = void 0;
|
|
7
|
+
var pako_1 = require("pako");
|
|
8
|
+
var json_bigint_1 = __importDefault(require("json-bigint"));
|
|
9
|
+
var constants_1 = require("./constants");
|
|
10
|
+
exports.isBrowser = typeof window !== 'undefined';
|
|
11
|
+
var btoaUniversal = function (b) {
|
|
12
|
+
return exports.isBrowser ? btoa(String.fromCharCode.apply(null, b)) : Buffer.from(b).toString('base64');
|
|
13
|
+
};
|
|
14
|
+
exports.btoaUniversal = btoaUniversal;
|
|
15
|
+
function randomIntFromInterval(min, max) {
|
|
16
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
17
|
+
}
|
|
18
|
+
exports.randomIntFromInterval = randomIntFromInterval;
|
|
19
|
+
function randomAddress() {
|
|
20
|
+
return "0x" + randomIntFromInterval(constants_1.CONTRACT_ADDRESS_LOWER_BOUND, constants_1.CONTRACT_ADDRESS_UPPER_BOUND).toString(16);
|
|
21
|
+
}
|
|
22
|
+
exports.randomAddress = randomAddress;
|
|
23
|
+
function makeAddress(input) {
|
|
24
|
+
return "0x" + input.replace(/^0x/, '').toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
exports.makeAddress = makeAddress;
|
|
27
|
+
exports.JsonParser = (0, json_bigint_1.default)({
|
|
28
|
+
alwaysParseAsBig: true,
|
|
29
|
+
useNativeBigInt: true,
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Function to compress compiled cairo program
|
|
33
|
+
*
|
|
34
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/gateway/transaction.py#L54-L58)
|
|
35
|
+
* @param jsonProgram - json file representing the compiled cairo program
|
|
36
|
+
* @returns Compressed cairo program
|
|
37
|
+
*/
|
|
38
|
+
function compressProgram(jsonProgram) {
|
|
39
|
+
var stringified = typeof jsonProgram === 'string' ? jsonProgram : exports.JsonParser.stringify(jsonProgram);
|
|
40
|
+
var compressedProgram = (0, pako_1.gzip)(stringified);
|
|
41
|
+
var base64 = (0, exports.btoaUniversal)(compressedProgram);
|
|
42
|
+
return base64;
|
|
43
|
+
}
|
|
44
|
+
exports.compressProgram = compressProgram;
|