Socket
Socket
Sign inDemoInstall

starknet

Package Overview
Dependencies
Maintainers
1
Versions
220
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

starknet - npm Package Compare versions

Comparing version 0.1.4 to 1.1.0

__mocks__/ArgentAccount.json

53

__tests__/index.test.ts

@@ -1,3 +0,14 @@

import * as starknet from '../index';
import fs from 'fs';
import starknet, {
CompiledContract,
compressProgram,
randomAddress,
makeAddress,
JsonParser,
} from '..';
const compiledArgentAccount = JsonParser.parse(
fs.readFileSync('./__mocks__/ArgentAccount.json').toString('ascii')
);
describe('starknet endpoints', () => {

@@ -32,8 +43,42 @@ describe('feeder gateway endpoints', () => {

});
xtest('addTransaction()', () => {});
});
describe('gateway endpoints', () => {
xtest('addTransaction()', () => {});
describe('addTransaction()', () => {
test('type: "DEPLOY"', async () => {
const inputContract = compiledArgentAccount as unknown as CompiledContract;
const contractDefinition = {
...inputContract,
program: compressProgram(inputContract.program),
};
const response = await starknet.addTransaction({
type: 'DEPLOY',
contract_address: randomAddress(),
contract_definition: contractDefinition,
});
expect(response.code).toBe('TRANSACTION_RECEIVED');
expect(response.tx_id).toBeGreaterThan(0);
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
// eslint-disable-next-line no-console
console.log('txId:', response.tx_id);
});
xtest('type: "INVOKE_FUNCTION"', () => {});
test('deployContract()', async () => {
const inputContract = compiledArgentAccount as unknown as CompiledContract;
const response = await starknet.deployContract(
inputContract,
makeAddress('0x20b5B1b8aFd65F1FCB755a449000cFC4aBCA0D40')
);
expect(response.code).toBe('TRANSACTION_RECEIVED');
expect(response.tx_id).toBeGreaterThan(0);
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
// eslint-disable-next-line no-console
console.log('txId:', response.tx_id);
});
});
});

30

dist/index.d.ts

@@ -0,1 +1,3 @@

import { compressProgram } from './utils';
import type { GetBlockResponse, GetCode, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Transaction, AddTransactionResponse, CompiledContract } from './types';
/**

@@ -5,5 +7,5 @@ * Gets the smart contract address on the goerli testnet.

* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
* @returns starknet smart contract address
* @returns starknet smart contract addresses
*/
export declare function getContractAddresses(): Promise<object>;
export declare function getContractAddresses(): Promise<GetContractAddressesResponse>;
/**

@@ -27,3 +29,3 @@ * Calls a function on the StarkNet contract.

*/
export declare function getBlock(blockId: number): Promise<object>;
export declare function getBlock(blockId: number): Promise<GetBlockResponse>;
/**

@@ -36,5 +38,5 @@ * Gets the code of the deployed contract.

* @param blockId
* @returns ABI of compiled contract in JSON
* @returns Bytecode and ABI of compiled contract
*/
export declare function getCode(contractAddress: string, blockId: number): Promise<object>;
export declare function getCode(contractAddress: string, blockId: number): Promise<GetCode>;
/**

@@ -59,3 +61,3 @@ * Gets the contract's storage variable at a specific key.

*/
export declare function getTransactionStatus(txId: number): Promise<object>;
export declare function getTransactionStatus(txId: number): Promise<GetTransactionStatusResponse>;
/**

@@ -69,3 +71,3 @@ * Gets the transaction information from a tx id.

*/
export declare function getTransaction(txId: number): Promise<object>;
export declare function getTransaction(txId: number): Promise<GetTransactionResponse>;
/**

@@ -79,3 +81,13 @@ * Invoke a function on the starknet contract

*/
export declare function addTransaction(tx: object): Promise<object>;
export declare function addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
/**
* Deploys a given compiled contract (json) to starknet
*
* @param contract - a json object containing the compiled contract
* @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
* @returns a confirmation of sending a transaction on the starknet contract
*/
export declare function deployContract(contract: CompiledContract | string, address?: string): Promise<AddTransactionResponse>;
export * from './utils';
export * from './types';
declare const _default: {

@@ -90,3 +102,5 @@ getContractAddresses: typeof getContractAddresses;

addTransaction: typeof addTransaction;
compressProgram: typeof compressProgram;
deployContract: typeof deployContract;
};
export default _default;
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -6,5 +27,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.addTransaction = exports.getTransaction = exports.getTransactionStatus = exports.getStorageAt = exports.getCode = exports.getBlock = exports.callContract = exports.getContractAddresses = void 0;
exports.deployContract = exports.addTransaction = exports.getTransaction = exports.getTransactionStatus = exports.getStorageAt = exports.getCode = exports.getBlock = exports.callContract = exports.getContractAddresses = void 0;
var axios_1 = __importDefault(require("axios"));
var API_URL = 'https://alpha2.starknet.io/';
var utils_1 = require("./utils");
var API_URL = 'https://alpha2.starknet.io';
var FEEDER_GATEWAY_URL = API_URL + "/feeder_gateway";

@@ -16,3 +38,3 @@ var GATEWAY_URL = API_URL + "/gateway";

* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
* @returns starknet smart contract address
* @returns starknet smart contract addresses
*/

@@ -30,2 +52,3 @@ function getContractAddresses() {

exports.getContractAddresses = getContractAddresses;
// TODO: add proper type
/**

@@ -77,3 +100,3 @@ * Calls a function on the StarkNet contract.

* @param blockId
* @returns ABI of compiled contract in JSON
* @returns Bytecode and ABI of compiled contract
*/

@@ -91,2 +114,3 @@ function getCode(contractAddress, blockId) {

exports.getCode = getCode;
// TODO: add proper type
/**

@@ -170,2 +194,22 @@ * Gets the contract's storage variable at a specific key.

exports.addTransaction = addTransaction;
/**
* Deploys a given compiled contract (json) to starknet
*
* @param contract - a json object containing the compiled contract
* @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
* @returns a confirmation of sending a transaction on the starknet contract
*/
function deployContract(contract, address) {
if (address === void 0) { address = (0, utils_1.randomAddress)(); }
var parsedContract = typeof contract === 'string' ? utils_1.JsonParser.parse(contract) : contract;
var contractDefinition = __assign(__assign({}, parsedContract), { program: (0, utils_1.compressProgram)(parsedContract.program) });
return addTransaction({
type: 'DEPLOY',
contract_address: address,
contract_definition: contractDefinition,
});
}
exports.deployContract = deployContract;
__exportStar(require("./utils"), exports);
__exportStar(require("./types"), exports);
exports.default = {

@@ -180,2 +224,4 @@ getContractAddresses: getContractAddresses,

addTransaction: addTransaction,
compressProgram: utils_1.compressProgram,
deployContract: deployContract,
};
{
"name": "starknet",
"version": "0.1.4",
"version": "1.1.0",
"description": "JavaScript library for StarkNet",

@@ -8,7 +8,11 @@ "main": "dist/index.js",

"scripts": {
"prepare": "npm run build",
"prepare": "npm run build && husky install",
"build": "tsc",
"pretest": "npm run lint",
"test": "jest",
"posttest": "npm run format",
"test:watch": "jest --watch",
"docs": "typedoc --theme ./node_modules/typedoc-github-wiki-theme/dist --readme none --name 'StarkNet.js Docs' --excludeNotDocumented"
"docs": "typedoc --readme none --name 'StarkNet.js Docs' --excludeNotDocumented --disableSources",
"format": "prettier --loglevel warn --write \"**/*.{ts,js,md,yml,json}\"",
"lint": "eslint . --cache --fix --ext .ts"
},

@@ -28,3 +32,12 @@ "keywords": [

"@babel/preset-typescript": "^7.15.0",
"@commitlint/cli": "^13.2.1",
"@commitlint/config-conventional": "^13.2.0",
"@semantic-release/changelog": "^6.0.0",
"@semantic-release/commit-analyzer": "^9.0.1",
"@semantic-release/git": "^10.0.0",
"@semantic-release/npm": "^8.0.2",
"@semantic-release/release-notes-generator": "^10.0.2",
"@types/jest": "^27.0.2",
"@types/json-bigint": "^1.0.1",
"@types/pako": "^1.0.2",
"@typescript-eslint/eslint-plugin": "^5.0.0",

@@ -34,9 +47,11 @@ "@typescript-eslint/parser": "^5.0.0",

"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-airbnb-typescript": "^14.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.2",
"jest": "^27.3.0",
"lint-staged": "^11.2.3",
"prettier": "^2.4.1",
"typedoc": "^0.22.6",
"typedoc-github-wiki-theme": "^0.6.0",
"typedoc-plugin-markdown": "^3.11.3",

@@ -46,4 +61,13 @@ "typescript": "^4.4.4"

"dependencies": {
"axios": "^0.23.0"
"axios": "^0.23.0",
"json-bigint": "^1.0.0",
"pako": "^2.0.4"
},
"lint-staged": {
"*.ts": "eslint --cache --fix",
"*.{ts,js,md,yml,json}": "prettier --write"
},
"jest": {
"testTimeout": 20000
}
}

@@ -11,17 +11,35 @@ <!-- logo -->

<p align="center">
<img src='https://img.shields.io/github/package-json/v/seanjameshan/starknet.js?label=npm' />
<img src='https://img.shields.io/bundlephobia/minzip/starknet?color=success&label=size' />
<!-- <img src='https://img.shields.io/npm/dt/starknet?color=blueviolet' /> -->
<img src="https://img.shields.io/badge/license-MIT-black">
<img src='https://img.shields.io/github/stars/seanjameshan/starknet.js?color=yellow' />
<img src='https://img.shields.io/github/followers/seanjameshan?color=red' />
<img src="https://img.shields.io/badge/powered_by-StarkWare-navy">
<a href="https://github.com/seanjameshan/starknet.js/actions">
<img src="https://img.shields.io/github/workflow/status/seanjameshan/starknet.js/Release">
</a>
<a href="https://www.npmjs.com/package/starknet">
<img src='https://img.shields.io/github/package-json/v/seanjameshan/starknet.js?label=npm' />
</a>
<a href="https://bundlephobia.com/package/starknet">
<img src='https://img.shields.io/bundlephobia/minzip/starknet?color=success&label=size' />
</a>
<a href="https://www.npmjs.com/package/starknet">
<img src='https://img.shields.io/npm/dt/starknet?color=blueviolet' />
</a>
<a href="https://github.com/seanjameshan/starknet.js/blob/main/LICENSE/">
<img src="https://img.shields.io/badge/license-MIT-black">
</a>
<a href="https://github.com/seanjameshan/starknet.js/stargazers">
<img src='https://img.shields.io/github/stars/seanjameshan/starknet.js?color=yellow' />
</a>
<a href="https://starkware.co/">
<img src="https://img.shields.io/badge/powered_by-StarkWare-navy">
</a>
</p>
## 🕹ī¸ Usage
Install the starknet with `npm`
Install starknet with `npm`
```bash
$ npm install starknet
```
Import `starknet` and use the [API](https://github.com/seanjameshan/starknet.js/blob/main/docs/Home.md)
Import `starknet` and use the [API](docs)
```javascript

@@ -36,7 +54,13 @@ import starknet from 'starknet';

## 🌐 API
[Click Here](https://github.com/seanjameshan/starknet.js/blob/main/docs/Home.md)
[Click Here](docs)
## Contributing
If you consider to contribute to this project please read [CONTRIBUTING.md](CONTRIBUTING.md) first.
## License
Copyright (c) 2021 Sean James Han
Licensed under the MIT license.
Licensed under the [MIT license](LICENSE).
import axios from 'axios';
import { randomAddress, compressProgram, JsonParser } from './utils';
import type {
GetBlockResponse,
GetCode,
GetContractAddressesResponse,
GetTransactionResponse,
GetTransactionStatusResponse,
Transaction,
AddTransactionResponse,
CompiledContract,
} from './types';
const API_URL: string = 'https://alpha2.starknet.io/';
const FEEDER_GATEWAY_URL: string = `${API_URL}/feeder_gateway`;
const GATEWAY_URL: string = `${API_URL}/gateway`;
const API_URL = 'https://alpha2.starknet.io';
const FEEDER_GATEWAY_URL = `${API_URL}/feeder_gateway`;
const GATEWAY_URL = `${API_URL}/gateway`;

@@ -11,9 +22,9 @@ /**

* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
* @returns starknet smart contract address
* @returns starknet smart contract addresses
*/
export function getContractAddresses(): Promise<object> {
export function getContractAddresses(): Promise<GetContractAddressesResponse> {
return new Promise((resolve, reject) => {
axios
.get(`${FEEDER_GATEWAY_URL}/get_contract_addresses`)
.then((resp: any) => {
.get<GetContractAddressesResponse>(`${FEEDER_GATEWAY_URL}/get_contract_addresses`)
.then((resp) => {
resolve(resp.data);

@@ -25,2 +36,3 @@ })

// TODO: add proper type
/**

@@ -54,6 +66,6 @@ * Calls a function on the StarkNet contract.

*/
export function getBlock(blockId: number): Promise<object> {
export function getBlock(blockId: number): Promise<GetBlockResponse> {
return new Promise((resolve, reject) => {
axios
.get(`${FEEDER_GATEWAY_URL}/get_block?blockId=${blockId}`)
.get<GetBlockResponse>(`${FEEDER_GATEWAY_URL}/get_block?blockId=${blockId}`)
.then((resp: any) => {

@@ -73,9 +85,11 @@ resolve(resp.data);

* @param blockId
* @returns ABI of compiled contract in JSON
* @returns Bytecode and ABI of compiled contract
*/
export function getCode(contractAddress: string, blockId: number): Promise<object> {
export function getCode(contractAddress: string, blockId: number): Promise<GetCode> {
return new Promise((resolve, reject) => {
axios
.get(`${FEEDER_GATEWAY_URL}/get_code?contractAddress=${contractAddress}&blockId=${blockId}`)
.then((resp: any) => {
.get<GetCode>(
`${FEEDER_GATEWAY_URL}/get_code?contractAddress=${contractAddress}&blockId=${blockId}`
)
.then((resp) => {
resolve(resp.data);

@@ -87,2 +101,3 @@ })

// TODO: add proper type
/**

@@ -123,7 +138,9 @@ * Gets the contract's storage variable at a specific key.

*/
export function getTransactionStatus(txId: number): Promise<object> {
export function getTransactionStatus(txId: number): Promise<GetTransactionStatusResponse> {
return new Promise((resolve, reject) => {
axios
.get(`${FEEDER_GATEWAY_URL}/get_transaction_status?transactionId=${txId}`)
.then((resp: any) => {
.get<GetTransactionStatusResponse>(
`${FEEDER_GATEWAY_URL}/get_transaction_status?transactionId=${txId}`
)
.then((resp) => {
resolve(resp.data);

@@ -143,7 +160,7 @@ })

*/
export function getTransaction(txId: number): Promise<object> {
export function getTransaction(txId: number): Promise<GetTransactionResponse> {
return new Promise((resolve, reject) => {
axios
.get(`${FEEDER_GATEWAY_URL}/get_transaction?transactionId=${txId}`)
.then((resp: any) => {
.get<GetTransactionResponse>(`${FEEDER_GATEWAY_URL}/get_transaction?transactionId=${txId}`)
.then((resp) => {
resolve(resp.data);

@@ -163,3 +180,3 @@ })

*/
export function addTransaction(tx: object): Promise<object> {
export function addTransaction(tx: Transaction): Promise<AddTransactionResponse> {
return new Promise((resolve, reject) => {

@@ -175,2 +192,29 @@ axios

/**
* Deploys a given compiled contract (json) to starknet
*
* @param contract - a json object containing the compiled contract
* @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
* @returns a confirmation of sending a transaction on the starknet contract
*/
export function deployContract(
contract: CompiledContract | string,
address: string = randomAddress()
): Promise<AddTransactionResponse> {
const parsedContract =
typeof contract === 'string' ? (JsonParser.parse(contract) as CompiledContract) : contract;
const contractDefinition = {
...parsedContract,
program: compressProgram(parsedContract.program),
};
return addTransaction({
type: 'DEPLOY',
contract_address: address,
contract_definition: contractDefinition,
});
}
export * from './utils';
export * from './types';
export default {

@@ -185,2 +229,4 @@ getContractAddresses,

addTransaction,
compressProgram,
deployContract,
};

@@ -14,4 +14,9 @@ {

/* Language and Environment */
"target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": ["es2017", "es7", "es6", "dom"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"target": "es5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"es2017",
"es7",
"es6",
"dom"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
// "jsx": "preserve", /* Specify what JSX code is generated. */

@@ -28,3 +33,3 @@ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */

/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"module": "commonjs" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */

@@ -47,3 +52,3 @@ // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */

/* Emit */
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
// "declarationMap": true, /* Create sourcemaps for d.ts files. */

@@ -53,3 +58,3 @@ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */

// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
"outDir": "dist", /* Specify an output folder for all emitted files. */
"outDir": "dist" /* Specify an output folder for all emitted files. */,
// "removeComments": true, /* Disable emitting comments. */

@@ -75,8 +80,8 @@ // "noEmit": true, /* Disable emitting files from a compilation. */

// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */

@@ -103,9 +108,6 @@ // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */

// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["src/**/*"],
"exclude": [
"node_modules",
"**/*.test.ts"
],
"exclude": ["node_modules"],
"typedocOptions": {

@@ -112,0 +114,0 @@ "entryPoints": ["src/index.ts"],

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡ī¸ by Socket Inc