Skip to content

Commit

Permalink
feat(sdk): add initial base structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanosync committed Oct 23, 2023
1 parent 9e1fac8 commit d242a9b
Show file tree
Hide file tree
Showing 23 changed files with 583 additions and 13 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ npm install -g pnpm
pnpm i
```

### Running in Development Mode

Execute the following command below and it will run the build process in watch mode.

```bash
pnpm dev
```

## License & Disclaimer

By using `Ordit` (this repo), you (the user) agree to be bound by [the terms of this license](LICENSE).
1 change: 1 addition & 0 deletions apps/browser-tests/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/index";
12 changes: 12 additions & 0 deletions apps/browser-tests/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions apps/browser-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@ordzaar/ordit-sdk-browser-tests",
"version": "0.0.0",
"description": "SDK tests for simplified interaction with wallet APIs and inscription service",
"license": "MIT",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"keywords": [
"ordit",
"ordit-sdk",
"sdk"
],
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build:watch": "tsc && vite build --watch",
"preview": "vite preview"
},
"dependencies": {
"@ordzaar/ordit-sdk": "workspace:*"
}
}
11 changes: 11 additions & 0 deletions apps/browser-tests/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
async function main() {
const appRoot = document.getElementById("app");

if (!appRoot) {
return;
}

appRoot.innerHTML = "Browser Test";
}

main();
1 change: 1 addition & 0 deletions apps/browser-tests/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
27 changes: 27 additions & 0 deletions apps/browser-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"module": "ESNext",
"target": "ESNext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"composite": false,
"declaration": true,
"declarationMap": true,
"inlineSources": false,
"isolatedModules": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"rootDir": "./",
"outDir": "./dist",
"sourceMap": true
},
"include": ["./src", "./tests", "./src/types"],
"exclude": ["node_modules", "dist"]
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"clean": "turbo run clean",
"format": "prettier --write .",
"lint": "turbo run lint -- --fix",
"test": "turbo run test"
"test": "turbo run test",
"dev": "turbo run dev"
},
"devDependencies": {
"@changesets/changelog-github": "0.4.8",
Expand All @@ -19,8 +20,8 @@
"@stickyjs/turbo": "^1.3.4",
"@waveshq/standard-prettier": "^2.16.0",
"@waveshq/standard-web-linter": "^2.16.0",
"semver": "^7.5.4",
"husky": "^8.0.3",
"semver": "^7.5.4",
"typescript": "5.2.2",
"vite": "^4.4.11",
"vitest": "^0.34.6"
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/browser-wallets.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/browser-wallets/index";
1 change: 1 addition & 0 deletions packages/sdk/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dist/index";
32 changes: 24 additions & 8 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@
"name": "@ordzaar/ordit-sdk",
"version": "0.0.0",
"description": "SDK for simplified interaction with wallet APIs and inscription service",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./browser-wallets": {
"import": "./dist/browser-wallets.js",
"require": "./dist/browser-wallets.cjs"
}
},
"files": [
"dist"
"dist/*",
"index.d.ts",
"browser-wallets.d.ts"
],
"keywords": [
"ordit",
"ordit-sdk",
"sdk"
],
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build:watch": "tsc && vite build --watch",
"preview": "vite preview"
"dev": "pnpm clean && tsc && vite build --watch",
"build": "pnpm clean && tsc && vite build",
"build:watch": "pnpm clean && tsc && vite build --watch",
"preview": "vite preview",
"clean": "rm -rf dist"
},
"dependencies": {
"@bitcoinerlab/secp256k1": "1.0.5",
Expand All @@ -32,6 +47,7 @@
"sats-connect": "^1.1.1"
},
"devDependencies": {
"@types/node": "^20.8.6"
"@types/node": "^20.8.6",
"vite-plugin-dts": "^3.6.0"
}
}
2 changes: 2 additions & 0 deletions packages/sdk/src/browser-wallets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { wallet as unisat } from "./unisat";
export { wallet as xverse } from "./xverse";
6 changes: 6 additions & 0 deletions packages/sdk/src/browser-wallets/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface BrowserWallet {
isInstalled: () => Promise<boolean>;
getAddresses: () => Promise<void>;
signPsbt: () => Promise<void>;
signMessage: () => Promise<void>;
}
20 changes: 20 additions & 0 deletions packages/sdk/src/browser-wallets/unisat/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { BrowserWallet } from "../types";

async function isInstalled() {
return false;
}

async function getAddresses() {}

async function signPsbt() {}

async function signMessage() {}

const wallet: BrowserWallet = {
isInstalled,
getAddresses,
signPsbt,
signMessage,
};

export { wallet };
20 changes: 20 additions & 0 deletions packages/sdk/src/browser-wallets/xverse/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { BrowserWallet } from "../types";

async function isInstalled() {
return false;
}

async function getAddresses() {}

async function signPsbt() {}

async function signMessage() {}

const wallet: BrowserWallet = {
isInstalled,
getAddresses,
signPsbt,
signMessage,
};

export { wallet };
6 changes: 6 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { BrowserWallet } from "./browser-wallets/types";
export type { BrowserWallet };

const SDK_NAME = "ORDIT_SDK";

export { SDK_NAME };
23 changes: 23 additions & 0 deletions packages/sdk/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
declare interface Window {
unisat: Unisat;
ethereum: MetaMask;
}

type UnisatNetwork = "livenet" | "testnet";

type Unisat = {
getNetwork: () => Promise<UnisatNetwork>;
switchNetwork: (targetNetwork: UnisatNetwork) => Promise<void>;
requestAccounts: () => Promise<string[]>;
getPublicKey: () => Promise<string>;
signPsbt: (
hex: string,
{ autoFinalized }: Record<string, boolean>,
) => Promise<string>;
signMessage: (message: string) => Promise<string>;
};

type MetaMask = {
isMetaMask: boolean;
request: (options: { method: string; params?: any }) => Promise<any>;
};
4 changes: 2 additions & 2 deletions packages/sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"rootDir": "./",
"rootDir": "./src",
"outDir": "./dist",
"sourceMap": true
},
"include": ["./src", "./tests", "./src/types"],
"include": ["./src", "./src/types"],
"exclude": ["node_modules", "dist"]
}
1 change: 1 addition & 0 deletions packages/sdk/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions packages/sdk/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { resolve } from "path";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import * as packageJson from "./package.json";

export default defineConfig({
build: {
outDir: "dist",
lib: {
entry: {
index: resolve(__dirname, "src/index.ts"),
"browser-wallets": resolve(__dirname, "src/browser-wallets/index.ts"),
},
formats: ["es", "cjs"],
},
rollupOptions: {
external: Object.keys(packageJson.dependencies),
},
commonjsOptions: {
include: [/node_modules/],
},
},
plugins: [
dts({
insertTypesEntry: true,
}),
],
});
Loading

0 comments on commit d242a9b

Please sign in to comment.