Skip to content

Commit

Permalink
feat: support Rei Wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
wendychaung authored and Hanssen0 committed Aug 24, 2024
1 parent f712b1d commit 1027242
Show file tree
Hide file tree
Showing 23 changed files with 578 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/ccc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@ckb-ccc/nip07": "workspace:*",
"@ckb-ccc/okx": "workspace:*",
"@ckb-ccc/uni-sat": "workspace:*",
"@ckb-ccc/utxo-global": "workspace:*"
"@ckb-ccc/utxo-global": "workspace:*",
"@ckb-ccc/rei": "workspace:*"
}
}
5 changes: 5 additions & 0 deletions packages/ccc/src/assets/rei.svg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { encodeSvgToImgSrc } from "./utils.js";

export const REI_SVG = encodeSvgToImgSrc(
'<svg id="layer2" data-name="layer2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 88.24 70.95"><defs><style>.cls-1{fill:url(#linear_9)}.cls-2{fill:rgba(155,84,168,0)}</style><linearGradient id="linear_9" data-name="linear 9" x1="216.98" y1="-423.81" x2="170.95" y2="319.28" gradientTransform="translate(18.94 29.12) scale(.09 -.09)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#01f395"/><stop offset="1" stop-color="#01b56a"/></linearGradient></defs><g id="layer1" data-name="layer1"><g><rect class="cls-2" width="88.24" height="70.95"/><g><path class="cls-1" d="m19.08,0H4.9l49.8,70.95h14.19L19.08,0Z"/><path d="m69.08,44.08c9.93-2.84,16.92-9.85,16.92-21.5v-.2c0-6.18-2.12-11.44-5.87-15.29-4.56-4.45-11.54-7.08-20.46-7.08H24.09l7.97,11.37h26.59c9.22,0,14.7,4.12,14.7,11.72v.2c0,7.19-5.68,11.86-14.6,11.86h-9.98l25.11,35.79h14.37l-19.16-26.87Z"/><path d="m0,20.16l35.64,50.78h14.19L14.19,20.16H0Z"/></g></g></g></svg>',
);
1 change: 1 addition & 0 deletions packages/ccc/src/barrel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "@ckb-ccc/eip6963";
export * from "@ckb-ccc/joy-id";
export * from "@ckb-ccc/nip07";
export * from "@ckb-ccc/okx";
export * from "@ckb-ccc/rei";
export * from "@ckb-ccc/uni-sat";
export * from "@ckb-ccc/utxo-global";
export * from "./signersController.js";
11 changes: 11 additions & 0 deletions packages/ccc/src/signersController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { Eip6963 } from "@ckb-ccc/eip6963";
import { JoyId } from "@ckb-ccc/joy-id";
import { Nip07 } from "@ckb-ccc/nip07";
import { Okx } from "@ckb-ccc/okx";
import { Rei } from "@ckb-ccc/rei";
import { UniSat } from "@ckb-ccc/uni-sat";
import { UtxoGlobal } from "@ckb-ccc/utxo-global";
import { ETH_SVG } from "./assets/eth.svg.js";
import { JOY_ID_SVG } from "./assets/joy-id.svg.js";
import { METAMASK_SVG } from "./assets/metamask.svg.js";
import { NOSTR_SVG } from "./assets/nostr.svg.js";
import { OKX_SVG } from "./assets/okx.svg.js";
import { REI_SVG } from "./assets/rei.svg.js";
import { UNI_SAT_SVG } from "./assets/uni-sat.svg.js";
import { UTXO_GLOBAL_SVG } from "./assets/utxo-global.svg.js";

Expand Down Expand Up @@ -97,6 +99,15 @@ export class SignersController {
configs,
);

await this.addSigners(
wallets,
"Rei Wallet",
REI_SVG,
Rei.getReiSigners(client),
onUpdate,
configs,
);

await this.addSigners(
wallets,
"JoyID Passkey",
Expand Down
12 changes: 12 additions & 0 deletions packages/rei/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules/
misc/

tsconfig.json
tsconfig.*.json
eslint.config.mjs
.prettierrc
.prettierignore

tsconfig.tsbuildinfo
tsconfig.*.tsbuildinfo
.github/
13 changes: 13 additions & 0 deletions packages/rei/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules/

dist/
dist.commoonjs/

.npmignore
.prettierrc
tsconfig.json
eslint.config.mjs
.prettierrc

tsconfig.tsbuildinfo
.github/
5 changes: 5 additions & 0 deletions packages/rei/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": false,
"trailingComma": "all",
"plugins": ["prettier-plugin-organize-imports"]
}
45 changes: 45 additions & 0 deletions packages/rei/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<p align="center">
<a href="https://app.ckbccc.com/">
<img alt="Logo" src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/logo.svg" width="20%" />
</a>
</p>

<h1 align="center" style="font-size: 48px;">
CCC's support for REI Wallet
</h1>

<p align="center">
<a href="https://www.npmjs.com/package/@ckb-ccc/rei"><img
alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Frei"
/></a>
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-ecofund/ccc" />
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-ecofund/ccc/master" />
<img alt="GitHub deployments" src="https://img.shields.io/github/deployments/ckb-ecofund/ccc/production" />
<a href="https://app.ckbccc.com/"><img
alt="Demo" src="https://img.shields.io/website?url=https%3A%2F%2Fapp.ckbccc.com%2F&label=Demo"
/></a>
</p>

<p align="center">
"CCC - CKBers' Codebase" is the next step of "Common Chains Connector".
<br />
Empower yourself with CCC to discover the unlimited potential of CKB.
<br />
Interoperate with wallets from different chain ecosystems.
<br />
Fully enabling CKB's Turing completeness and cryptographic freedom power.
</p>

## Preview

<p align="center">
<a href="https://app.ckbccc.com/">
<img src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/preview.png" width="30%" />
</a>
</p>

This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://app.ckbccc.com/). It showcases how to use CCC for some basic scenarios in CKB.

<h3 align="center">
Read more about CCC on <a href="https://docs.ckbccc.com">our website</a> or <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
</h3>
29 changes: 29 additions & 0 deletions packages/rei/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier";

import { fileURLToPath } from "url";
import { dirname } from "path";

export default tseslint.config({
files: ["./src/**/*.ts"],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
],
rules: {
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-redundant-type-constituents": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/unbound-method": ["error", { "ignoreStatic": true }],
},
plugins: { prettier: eslintPluginPrettierRecommended },
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: dirname(fileURLToPath(import.meta.url)),
},
},
});
3 changes: 3 additions & 0 deletions packages/rei/misc/basedirs/dist.commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
3 changes: 3 additions & 0 deletions packages/rei/misc/basedirs/dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
55 changes: 55 additions & 0 deletions packages/rei/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@ckb-ccc/rei",
"version": "0.0.12-alpha.0",
"description": "CCC - CKBer's Codebase. Common Chains Connector's support for Rei",
"license": "MIT",
"private": false,
"homepage": "https://github.com/ckb-ecofund/ccc",
"repository": {
"type": "git",
"url": "git://github.com/ckb-ecofund/ccc.git"
},
"main": "dist.commonjs/index.js",
"module": "dist/index.js",
"exports": {
".": {
"import": "./dist/index.js",
"default": "./dist.commonjs/index.js"
},
"./barrel": {
"import": "./dist/barrel.js",
"default": "./dist.commonjs/barrel.js"
},
"./advanced": {
"import": "./dist/advanced.js",
"default": "./dist.commonjs/advanced.js"
},
"./advancedBarrel": {
"import": "./dist/advancedBarrel.js",
"default": "./dist.commonjs/advancedBarrel.js"
}
},
"scripts": {
"build": "rimraf ./dist && rimraf ./dist.commonjs && tsc && tsc --project tsconfig.commonjs.json && copyfiles -u 2 misc/basedirs/**/* .",
"lint": "eslint",
"format": "prettier --write . && eslint --fix"
},
"devDependencies": {
"@eslint/js": "^9.1.1",
"copyfiles": "^2.4.1",
"eslint": "^9.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"rimraf": "^5.0.5",
"typescript": "^5.4.5",
"typescript-eslint": "^7.7.0"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@ckb-ccc/core": "workspace:*"
}
}
1 change: 1 addition & 0 deletions packages/rei/src/advanced.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as ReiA from "./advancedBarrel.js";
103 changes: 103 additions & 0 deletions packages/rei/src/advancedBarrel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { ccc } from "@ckb-ccc/core";

/**
* Interface representing a provider for interacting with accounts and signing messages.
* @interface
*/
export interface Provider {
/**
* Sends a request to the provider.
* @type {RequestMethod}
*/
request: RequestMethod;

/**
* Adds an event listener to the provider.
* @type {OnMethod}
*/
on: OnMethod;

/**
* Checks if rei wallet is connected.
* @returns A promise that resolves to true if connected, false otherwise.
*/
isConnected(): Promise<boolean>;

/**
* Removes an event listener from the provider.
* @param {string} eventName - The name of the event to remove the listener from.
* @param {(...args: unknown[]) => unknown} listener - The listener function to remove.
* @returns {Provider} The provider instance.
*/
off(eventName: string, listener: (...args: unknown[]) => unknown): void;
}

/**
* Interface representing a method to add event listeners to the provider.
* @interface
*/
export interface OnMethod {
/**
* Adds an event listener to the provider.
* @param {string} eventName - The name of the event.
* @param {(...args: unknown[]) => unknown} listener - The listener function.
* @returns {Provider} The provider instance.
*/
(eventName: string, listener: (...args: unknown[]) => unknown): void;
}

export interface RequestMethod {
/**
* Requests the accounts from the provider.
* @param request - The request object.
* @param request.method - The method name.
* @param request.data - The optional method parameters.
* @returns A promise that resolves to an array of account addresses.
*/
(request: {
method: "ckb_requestAccounts";
data?: undefined;
}): Promise<string>;

/**
* Signs a message with the personal account.
* @param request - The request object.
* @param request.method - The method name.
* @param request.data - The method parameters.
* @returns A promise that resolves to the signed message.
*/
(request: {
method: "ckb_signMessage";
data: { message: string };
}): Promise<ccc.Hex>;

/**
* Gets the identity of the signer.
* @param request - The request object.
* @param request.method - The method name.
* @returns A promise that resolves to the signed message.
*/
(request: { method: "ckb_getPublicKey" }): Promise<string>;

/**
* Get network.
* @param request - The request object.
* @param request.method - The method name.
* @param request.data - The method parameters.
* @returns A promise that resolves to the signed message.
*/
(request: {
method: "ckb_switchNetwork";
data: string;
}): Promise<{ type: string; network: string }>;

/**
* Signs transaction .
* @param request - The request object.
* @param request.method - The method name.
* @param request.data - The method parameters.
* @returns A promise that resolves to the signed message.
*/

(request: { method: "ckb_signTransaction"; data: any }): Promise<any>;
}
2 changes: 2 additions & 0 deletions packages/rei/src/barrel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./signer.js";
export * from "./signersFactory.js";
1 change: 1 addition & 0 deletions packages/rei/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as Rei from "./barrel.js";
Loading

0 comments on commit 1027242

Please sign in to comment.