Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starknet #17

Merged
merged 9 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"@irys/web-upload": "workspace:^",
"@irys/web-upload-ethereum": "workspace:^",
"@irys/web-upload-ethereum-ethers-v6": "workspace:^",
"@irys/web-upload-ethereum-viem-v2": "workspace:^"
"@irys/web-upload-ethereum-viem-v2": "workspace:^",
"@irys/upload-starknet-node":"workspace:^"
},
"version": "1.0.2",
"scripts": {},
Expand Down
11 changes: 10 additions & 1 deletion examples/node/scripts/test-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { canUploadUsdcEth } from "./tokens/usdcEth";
import { canUploadUsdcPolygon } from "./tokens/usdcPolygon";
import { canUploadChainlink } from "./tokens/chainlink";
import { canUploadSolana } from "./tokens/solana";
import {canUploadStarknet} from "./tokens/starknet"

const runTests = async () => {

Expand Down Expand Up @@ -96,8 +97,16 @@ const runTests = async () => {
const usdcPolygonResult = await canUploadUsdcPolygon();
if (usdcPolygonResult) console.log("USDC on Polygon upload test passed.");
else console.log("USDC on Polygon upload test failed.");


const uploadStarknet = await canUploadStarknet()
if(uploadStarknet)console.log("STRK on Starknet upload test passed.");
else console.log("STRK on Starknet upload test failed.");


};

runTests().catch((err) => console.error("Unexpected error during testing:", err));




37 changes: 37 additions & 0 deletions examples/node/scripts/tokens/starknet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Uploader } from "@irys/upload";
import { Starknet, StarknetEth, StarknetToken } from "@irys/upload-starknet-node";
import "dotenv/config";
JesseTheRobot marked this conversation as resolved.
Show resolved Hide resolved

/**
* Tests if data can be uploaded to Irys using USDCPolygon.
*
* @returns {Promise<boolean>} Returns true if upload is successful, otherwise false.
*/
export const canUploadStarknet = async (): Promise<boolean> => {3
JesseTheRobot marked this conversation as resolved.
Show resolved Hide resolved
try {
// Initialize the Irys Uploader with the Ethereum wallet
const irysUploader = await Uploader(Starknet).withWallet("0x005d5c250b5c181684ae6d8ebfa0faeac3ad0c6f31a6c2f102a2fffddba00a05");

// Attempt to upload data to Irys
//@ts-ignore
JesseTheRobot marked this conversation as resolved.
Show resolved Hide resolved
const receipt = await irysUploader.upload("hirys", {
tags: [{ name: "Content-Type", value: "text/plain" }],
});

console.log('reciept:', receipt)

// If an exception is not thrown, the upload was successful
// console.log(`Upload successful https://gateway.irys.xyz/${receipt.id}`);
return true;
} catch (error) {
console.error("Error during upload:", error);
return false;
}
};
const privateKey = "0x005d5c250b5c181684ae6d8ebfa0faeac3ad0c6f31a6c2f102a2fffddba00a05";
const address = "0x02F659cf8CCE41168B8c0A8BedCE468E33BE1B7bd26E920266C025Dc0F8FBD1b"

const TokenConfigTrimmed = {
JesseTheRobot marked this conversation as resolved.
Show resolved Hide resolved
privateKey,
address,
}
2 changes: 1 addition & 1 deletion packages/aptos-node/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class AptosConfig extends BaseNodeToken {
};
}

ownerToAddress(owner: any): string {
async ownerToAddress(owner: any): Promise<string> {
const hash = sha3.sha3_256.create();
hash.update(Buffer.from(owner));
hash.update("\x00");
Expand Down
6 changes: 3 additions & 3 deletions packages/aptos-web/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ export default class AptosConfig extends BaseWebToken {
};
}

ownerToAddress(owner: any): string {
async ownerToAddress(owner: any): Promise<string> {
const hash = sha3.sha3_256.create();
hash.update(Buffer.from(owner));
hash.update("\x00");
return `0x${hash.hex()}`;
return await `0x${hash.hex()}`;
JesseTheRobot marked this conversation as resolved.
Show resolved Hide resolved
}

async sign(data: Uint8Array): Promise<Uint8Array> {
Expand Down Expand Up @@ -249,7 +249,7 @@ export default class AptosConfig extends BaseWebToken {
// this.providerUrl is a Network enum type represents the current configured network
this.aptosConfig = new AptosSDKConfig({ network: this.providerUrl, ...this.config?.opts?.aptosSdkConfig });
this._publicKey = (await this.getPublicKey()) as Buffer;
this._address = this.ownerToAddress(this._publicKey);
this._address = await this.ownerToAddress(this._publicKey);

const client = await this.getProvider();

Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-web/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class EthereumConfig extends BaseWebToken {
};
}

ownerToAddress(owner: any): string {
ownerToAddress(owner: any): Promise<string> {
// return (
// "0x" +
// keccak256(Buffer.from(owner.slice(1)))
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class BaseEthereumToken extends BaseNodeToken {
};
}

ownerToAddress(owner: any): string {
async ownerToAddress(owner: any): Promise<string> {
return "0x" + keccak256(owner.slice(1)).slice(-20).toString("hex");
}

Expand Down
2 changes: 1 addition & 1 deletion packages/solana-node/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class SolanaConfig extends BaseNodeToken {
return tx;
}

ownerToAddress(owner: any): string {
async ownerToAddress(owner: any): Promise<string> {
return bs58.encode(owner);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/solana-web/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class SolanaConfig extends BaseWebToken {
return tx;
}

ownerToAddress(owner: any): string {
async ownerToAddress(owner: any): Promise<string> {
if (typeof owner === "string") {
owner = Buffer.from(owner);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/starknet-node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# starknet-node

TODO

## Installation

```sh
npm install @irys/upload-starknet-node
```
11 changes: 11 additions & 0 deletions packages/starknet-node/cjs.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../cjs.tsconfig.json",
"include": [
"src"
],
"compilerOptions": {
"outDir": "dist/cjs",
"rootDir": "./src",
"declaration": false
}
}
82 changes: 82 additions & 0 deletions packages/starknet-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@irys/upload-starknet-node",
"version": "0.0.0",
"description": "TODO",
"license": "MIT",
"sideEffects": false,
"module": "dist/esm/index.js",
"main": "dist/cjs/index.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./esm/*": {
"types": "./dist/types/*.d.ts",
"default": "./dist/esm/*.js"
},
"./cjs/*": {
"types": "./dist/types/*.d.ts",
"default": "./dist/cjs/*.js"
},
"./*": {
"types": "./dist/types/*.d.ts",
"import": {
"types": "./dist/types/*.d.ts",
"default": "./dist/esm/*.js"
},
"require": {
"types": "./dist/types/*.d.ts",
"default": "./dist/cjs/*.js"
}
}
},
"files": [
"/dist/cjs",
"/dist/esm",
"/dist/types",
"/src"
],
"scripts": {
"lint": "eslint --ext js,ts,tsx src",
"lint:fix": "eslint --fix --ext js,ts,tsx src",
"clean": "rimraf dist",
"build": "pnpm clean && concurrently \" tsc && sh ../../scripts/fix-pkg.sh esm module && tsc-esm-fix \" \" tsc -p test/tsconfig.json \" \"tsc -p cjs.tsconfig.json && sh ../../scripts/fix-pkg.sh cjs commonjs \"",
"test": "ava"
},
"dependencies": {
"@irys/bundles": "^0.0.2",
"@irys/upload": "workspace:^",
"@irys/upload-core": "workspace:^",
"bignumber.js": "^9.1.2",
"starknet": "^6.17.0"
},
"devDependencies": {
"@ava/typescript": "^5.0.0",
"ava": "^6.1.3"
},
"publishConfig": {
"access": "public"
},
"author": "Irys maintainers <hello@irys.xyz>",
"homepage": "https://irys.xyz",
"repository": {
"url": "https://github.com/irys-xyz/js-sdk.git"
},
"typedoc": {
"entryPoint": "./src/index.ts",
"readmeFile": "./README.md",
"displayName": "starknet-node"
},
"ava": {
"typescript": {
"compile": false,
"rewritePaths": {
"src/": "dist/test/src/",
"test/": "dist/test/test/"
}
}
}
}
19 changes: 19 additions & 0 deletions packages/starknet-node/src/abi/argent.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"name": "argent::account::interface::IArgentUserAccount",
"type": "interface",
"items": [
{
"name": "get_owner",
"type": "function",
"inputs": [],
"outputs": [
{
"type": "core::felt252"
}
],
"state_mutability": "view"
}
]
}
]
17 changes: 17 additions & 0 deletions packages/starknet-node/src/abi/braavos.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[ {
"name": "braavos_account::signers::interface::ISignerManagement",
"type": "interface",
"items": [
{
"name": "get_public_key",
"type": "function",
"inputs": [],
"outputs": [
{
"type": "core::felt252"
}
],
"state_mutability": "view"
}
]
}]
Loading