Skip to content

Commit

Permalink
Merge branch 'main' into 31-add-a-nextjs-example-project-with-wallet-…
Browse files Browse the repository at this point in the history
…and-staking-integration
  • Loading branch information
marc-aurele-besner committed Jul 2, 2024
2 parents c9ca104 + 4e88570 commit 1ef83f5
Show file tree
Hide file tree
Showing 36 changed files with 3,550 additions and 94 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish Packages

on:
push:
branches:
- main
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'yarn'

- name: Install dependencies
run: yarn install

- name: Configure npm
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

- name: Build packages
run: yarn build

- name: Version bump and tag
run: yarn publish

- name: Publish packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
packages=("packages/@autonomys/auto-utils")
for package in "${packages[@]}"; do
echo "Publishing $package"
cd $package
npm publish --access public
cd ../..
done
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ packages/*/node_modules/
# Yarn cache
.yarn/cache/*
.yarnrc.yml
.yarn/install-state.gz

# TypeScript build outputs
dist/
Expand Down
5 changes: 5 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "0.1.3-alpha.1",
"npmClient": "yarn"
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"examples/*"
],
"scripts": {
"build": "yarn workspaces foreach --all run build",
"clean": "yarn workspaces foreach --all run clean",
"format": "yarn workspaces foreach --all run format",
"test": "yarn workspaces foreach --all run test"
"build": "lerna run build",
"clean": "lerna run clean",
"format": "lerna run format",
"test": "lerna run test",
"publish": "lerna publish --no-private"
},
"packageManager": "[email protected]",
"engines": {
Expand All @@ -29,6 +30,7 @@
"@types/jest": "^29.5.12",
"eslint": "^8.57.0",
"jest": "^29.7.0",
"lerna": "^8.1.5",
"prettier": "^3.2.5",
"ts-jest": "^29.1.4",
"typescript": "^5.4.5"
Expand Down
32 changes: 31 additions & 1 deletion packages/auto-consensus/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
# @autonomys/auto-consensus
# Autonomys Auto Consensus SDK

## Overview

The Autonomys Auto Consensus SDK provides functionalities for blockchain consensus interactions, including address management, balance retrieval, staking, and transfers.

## Address Management

- `generateAddress(input: MnemonicOrURI): string`: Generates a new address.

## Balances

- `getBalance(address: string): Promise<Balance>`: Retrieves the balance of an address.

## Staking

- `stake(address: string, amount: number): Promise<void>`: Stakes an amount from an address.

## Transfers

- `transfer(from: string, to: string, amount: number): Promise<void>`: Transfers an amount from one address to another.

## Info

- `getInfo(): Promise<Info>`: Retrieves blockchain information.

## Import Example

```typescript
import { generateAddress, getBalance, stake, transfer, getInfo } from '@autonomys/auto-consensus'
```
7 changes: 4 additions & 3 deletions packages/auto-consensus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autonomys/auto-consensus",
"version": "0.1.0",
"version": "0.1.3-alpha.1",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
Expand All @@ -21,7 +21,7 @@
"url": "https://www.autonomys.net"
},
"dependencies": {
"@autonomys/auto-utils": "workspace:*"
"@autonomys/auto-utils": "^0.1.3-alpha.1"
},
"devDependencies": {
"@polkadot/types-codec": "^11.2.1",
Expand All @@ -31,5 +31,6 @@
"prettier": "^3.2.5",
"ts-jest": "^29.1.4",
"typescript": "^5.4.5"
}
},
"gitHead": "040b7e1835cbdc80a897e37f03579901dbb50243"
}
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/address.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/address.ts

import { encodeAddress } from '@polkadot/keyring'

export const address = (address: string | Uint8Array): string => encodeAddress(address, 2254)
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/balances.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/balances.ts

import { activate } from '@autonomys/auto-utils'
import type { ApiPromise } from '@polkadot/api'
import type { BN } from '@polkadot/util'
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/index.ts

export * from './address'
export * from './balances'
export * from './info'
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/info.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/info.ts

import { activate } from '@autonomys/auto-utils'

export const networkTimestamp = async (networkId?: string) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/staking.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/staking.ts

import type { ApiPromise } from '@polkadot/api'
import type { KeyringPair } from '@polkadot/keyring/types'
import type { StorageKey } from '@polkadot/types'
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/transfer.ts

import type { ApiPromise } from '@polkadot/api'

export type Amount = BigInt | number | string
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/types/events.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/types/events.ts

export type ActionEvents = string | string[]
export type Events = ActionEvents | ActionEvents[]

Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// file: src/types/index.ts

export * from './events'
export * from './transaction'
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/types/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/types/transaction.ts

import type { Events } from '../types/events'

export type EventsValidated = {
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/utils/detectTxSuccess.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/utils/detectTxSuccess.ts

import type { EventRecord } from '@polkadot/types/interfaces'
import { expectSuccessfulTxEvent } from './events'

Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/utils/events.ts

import type { ActionEvents, EventKeys } from '../types/events'

// Enum for Event Types
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/utils/index.ts

export * from './detectTxSuccess'
export * from './events'
export * from './signAndSendTx'
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/utils/signAndSendTx.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/utils/signAndSendTx.ts

import type { AddressOrPair, SubmittableExtrinsic } from '@polkadot/api/types'
import type { ISubmittableResult } from '@polkadot/types/types'
import type { Events } from '../types/events'
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/utils/sudo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/utils/sudo.ts

import { ApiPromise } from '@polkadot/api'
import type { AddressOrPair, SubmittableExtrinsic } from '@polkadot/api/types'
import type { ISubmittableResult } from '@polkadot/types/types'
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-consensus/src/utils/validateEvents.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/utils/validateEvents.ts

import type { EventRecord } from '@polkadot/types/interfaces'
import type { Events } from '../types/events'
import type { EventsValidated } from '../types/transaction'
Expand Down
7 changes: 4 additions & 3 deletions packages/auto-id/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autonomys/auto-id",
"version": "0.1.0",
"version": "0.1.3-alpha.1",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
Expand All @@ -9,7 +9,7 @@
"test": "jest"
},
"dependencies": {
"@autonomys/auto-utils": "workspace:*",
"@autonomys/auto-utils": "^0.1.3-alpha.1",
"@peculiar/asn1-schema": "^2.3.8",
"@peculiar/asn1-x509": "^2.3.8",
"@peculiar/webcrypto": "^1.5.0",
Expand All @@ -27,5 +27,6 @@
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
},
"gitHead": "040b7e1835cbdc80a897e37f03579901dbb50243"
}
57 changes: 56 additions & 1 deletion packages/auto-utils/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
# @autonomys/auto-utils
# Autonomys Auto SDK Utility

## Overview

The Autonomys Auto SDK Utility provides functionalities for wallet setup, network management, data storage, cryptographic operations, and API activation.

## Wallet Management

- `setupWallet(input: MnemonicOrURI): Promise<KeyringPair>`: Initializes a wallet using a mnemonic or URI.
- `activateWallet(input: ActivateWalletInput): Promise<WalletActivated>`: Activates a wallet and returns API and accounts.
- `mockWallets(network: NetworkInput | DomainInput): Promise<WalletActivated[]>`: Creates mock wallets for testing.
- `getMockWallet(name: string, wallets: WalletActivated[]): WalletActivated`: Retrieves a mock wallet by name.

## Network Management

- `getNetworkDetails(input?: NetworkInput): Network`: Gets network details.
- `getNetworkRpcUrls(input?: NetworkInput): string[]`: Gets network RPC URLs.
- `getNetworkDomainDetails(input: DomainInput): Domain`: Gets domain details.
- `getNetworkDomainRpcUrls(input: DomainInput): string[]`: Gets domain RPC URLs.

## Data Storage

- `save(key: string, value: any)`: Saves data to local storage or file system.
- `read(key: string): any`: Reads data from local storage or file system.

## Cryptographic Functions

- `blake2b_256(data: Uint8Array): string`: Hashes data with BLAKE2b-256.
- `stringToUint8Array(text: string): Uint8Array`: Converts a string to a Uint8Array.
- `concatenateUint8Arrays(array1: Uint8Array, array2: Uint8Array): Uint8Array`: Concatenates two Uint8Arrays.

## API Activation

- `activate(input?: NetworkInput): Promise<ApiPromise>`: Activates the API for a network.
- `activateDomain(input: DomainInput): Promise<ApiPromise>`: Activates the API for a domain.
- `disconnect()`: Disconnects the API.
- `disconnectDomain()`: Disconnects the domain API.

## Constants

- `networks`: Array of network configurations.
- `defaultNetwork`: Default network configuration.
- `mockURIs`: Array of mock URIs.

## Types

- `Network`, `Domain`, `Explorer`, `NetworkInput`, `DomainInput`
- `Mnemonic`, `URI`, `AppName`, `MnemonicOrURI`

For more details, refer to the source files in the `src` directory.

## Import Example

```typescript
import { activateWallet } from '@autonomys/auto-utils'
```
5 changes: 3 additions & 2 deletions packages/auto-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autonomys/auto-utils",
"version": "0.1.0",
"version": "0.1.3-alpha.1",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
Expand Down Expand Up @@ -35,5 +35,6 @@
},
"browser": {
"fs": false
}
},
"gitHead": "040b7e1835cbdc80a897e37f03579901dbb50243"
}
2 changes: 2 additions & 0 deletions packages/auto-utils/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/constants/index.ts

export * from './network'
export * from './token'
export * from './wallet'
2 changes: 2 additions & 0 deletions packages/auto-utils/src/constants/network.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/constants/network.ts

import type { Network } from '../types/network'

export const networks: Network[] = [
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-utils/src/constants/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/constants/wallet.ts

export const mockURIs = [
'//Alice',
'//Bob',
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-utils/src/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/crypto.ts

import { blake2AsHex } from '@polkadot/util-crypto'

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/index.ts

export * from './api'
export * from './crypto'
export * from './network'
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-utils/src/network.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/network.ts

import { defaultNetwork, networks } from './constants/network'
import type { DomainInput, NetworkInput } from './types/network'

Expand Down
6 changes: 4 additions & 2 deletions packages/auto-utils/src/read.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/read.ts

export const read = async (key: string) => {
// detect if we are in the browser or in node
if (typeof window !== 'undefined') return readFromLocalStorage(key)
Expand All @@ -22,9 +24,9 @@ export const readFromFileSystem = async (key: string) => {
const fs = await import('fs/promises')
try {
const data = await fs.readFile(key, { encoding: 'utf-8' })
return JSON.parse(data);
return JSON.parse(data)
} catch (error) {
throw new Error('Failed to read or parse file: ' + error)
}
} else throw new Error('This function can only be used in node')
}
}
2 changes: 2 additions & 0 deletions packages/auto-utils/src/save.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/save.ts

export const save = async (key: string, value: any) => {
// detect if we are in the browser or in node
if (typeof window !== 'undefined') await saveOnLocalStorage(key, value)
Expand Down
2 changes: 2 additions & 0 deletions packages/auto-utils/src/types/network.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// file: src/types/network.ts

export type Explorer = {
name: string
url: string
Expand Down
Loading

0 comments on commit 1ef83f5

Please sign in to comment.