-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Base chain support for Superfluid (#182)
* feat: create base package * [CORE] feat: add Base Blockchain * [CORE] v1.0.4 * [EVM] feat: Add Base + ETH Sepolia chains data * [EVM] v1.0.4 * feat: generalize SuperfluidAccount to handle EVM Accounts * [SUPERFLUID] v1.1.0 * [EVM] feat: add chain when not listed on connect * Fix: message.chain=ETH for all EVM chains messages (else rejected) * Fix: message.chain=ETH for all EVM chains messages (else rejected) --------- Co-authored-by: philogicae <[email protected]>
- Loading branch information
1 parent
9703fe7
commit ed1ef77
Showing
20 changed files
with
579 additions
and
232 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
"messages", | ||
"ethereum", | ||
"solana", | ||
"avalanche", | ||
"avax", | ||
"base", | ||
"defi", | ||
"dao", | ||
"nft" | ||
|
@@ -32,7 +35,8 @@ | |
"Roman Gascoin <[email protected]>", | ||
"Mike Hukiewitz <[email protected]>", | ||
"Kelian Christophe <[email protected]>", | ||
"Angel Manzano <[email protected]>" | ||
"Angel Manzano <[email protected]>", | ||
"Gerard Molina <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"engines": { | ||
|
@@ -73,6 +77,7 @@ | |
"packages/ethereum", | ||
"packages/ethereum-ledger", | ||
"packages/avalanche", | ||
"packages/base", | ||
"packages/nuls2", | ||
"packages/cosmos", | ||
"packages/solana", | ||
|
@@ -83,4 +88,4 @@ | |
"packages/client", | ||
"packages/dns" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# @aleph-sdk/base | ||
|
||
This package provides an implementation for Base blockchain accounts within the Aleph.im ecosystem, enabling Base account management and message signing functionalities. | ||
|
||
See [@aleph-sdk/client](https://npmjs.com/package/@aleph-sdk/client) or the [offical docs](https://docs.aleph.im) as the entrypoint for developing with aleph.im. | ||
|
||
## Features | ||
|
||
As Base Account extends from Ethereum account, see [@aleph-sdk/ethereum](https://www.npmjs.com/package/@aleph-sdk/ethereum) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import * as bip39 from 'bip39' | ||
import { ethers } from 'ethers' | ||
|
||
import * as base from '../src' | ||
import { PostMessageBuilder, prepareAlephMessage, ItemType } from '../../message/src' | ||
import { EthereumMockProvider } from '@aleph-sdk/evm' | ||
import { EphAccount } from '@aleph-sdk/account' | ||
|
||
async function createEphemeralEth(): Promise<EphAccount> { | ||
const mnemonic = bip39.generateMnemonic() | ||
const { address, publicKey, privateKey } = ethers.Wallet.fromMnemonic(mnemonic) | ||
|
||
return { | ||
address, | ||
publicKey, | ||
privateKey: privateKey.substring(2), | ||
mnemonic, | ||
} | ||
} | ||
|
||
describe('Ethereum accounts', () => { | ||
let ephemeralAccount: EphAccount | ||
|
||
beforeAll(async () => { | ||
ephemeralAccount = await createEphemeralEth() | ||
}) | ||
|
||
it('should import a base account using a mnemonic', () => { | ||
const { account, mnemonic } = base.newAccount() | ||
const accountFromMnemonic = base.importAccountFromMnemonic(mnemonic) | ||
|
||
expect(account.address).toStrictEqual(accountFromMnemonic.address) | ||
}) | ||
|
||
it('should import a base account using a private key', () => { | ||
const mnemonic = bip39.generateMnemonic() | ||
const wallet = ethers.Wallet.fromMnemonic(mnemonic) | ||
const accountFromPrivate = base.importAccountFromPrivateKey(wallet.privateKey) | ||
|
||
expect(wallet.address).toStrictEqual(accountFromPrivate.address) | ||
}) | ||
|
||
it('should import a base account using a provider', async () => { | ||
const { address, privateKey } = ephemeralAccount | ||
if (!privateKey) throw Error('Can not retrieve privateKey inside ephemeralAccount.json') | ||
|
||
const provider = new EthereumMockProvider({ | ||
address, | ||
privateKey, | ||
networkVersion: 31, | ||
}) | ||
|
||
const accountFromProvider = await base.getAccountFromProvider(provider) | ||
const accountFromPrivate = base.importAccountFromPrivateKey(privateKey) | ||
|
||
expect(accountFromProvider.address).toStrictEqual(accountFromPrivate.address) | ||
}) | ||
|
||
it('should get the same signed message for each account', async () => { | ||
const { address, privateKey } = ephemeralAccount | ||
if (!privateKey) throw Error('Can not retrieve privateKey inside ephemeralAccount.json') | ||
|
||
const provider = new EthereumMockProvider({ | ||
address, | ||
privateKey, | ||
networkVersion: 31, | ||
}) | ||
const { account, mnemonic } = base.newAccount() | ||
const accountFromProvider = await base.getAccountFromProvider(provider) | ||
const accountFromPrivate = await base.importAccountFromMnemonic(mnemonic) | ||
|
||
const builtMessage = PostMessageBuilder({ | ||
account, | ||
channel: 'TEST', | ||
storageEngine: ItemType.inline, | ||
timestamp: Date.now() / 1000, | ||
content: { address: account.address, time: 15, type: '' }, | ||
}) | ||
|
||
const hashedMessage = await prepareAlephMessage({ | ||
message: builtMessage, | ||
}) | ||
|
||
expect(account.sign(hashedMessage)).toStrictEqual(accountFromPrivate.sign(hashedMessage)) | ||
expect(account.sign(hashedMessage)).toStrictEqual(accountFromProvider.sign(hashedMessage)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@aleph-sdk/base", | ||
"version": "1.0.0", | ||
"description": "Base accounts for signing messages on aleph.im", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"@types/sha.js": "^2.4.0" | ||
}, | ||
"dependencies": { | ||
"eciesjs": "^0.4.6", | ||
"sha.js": "^2.4.11" | ||
}, | ||
"peerDependencies": { | ||
"@aleph-sdk/account": "^1.x.x", | ||
"@aleph-sdk/core": "^1.0.4", | ||
"@aleph-sdk/evm": "^1.0.4", | ||
"@aleph-sdk/ethereum": "^1.x.x", | ||
"avalanche": "^3.15.3", | ||
"ethers": "^5.x.x" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"rollup": "rollup -c ../../rollup.config.js", | ||
"build": "npm run rollup" | ||
}, | ||
"author": "", | ||
"homepage": "https://aleph.im", | ||
"bugs": "https://github.com/aleph-im/aleph-sdk-ts/issues", | ||
"license": "MIT" | ||
} |
Oops, something went wrong.