Skip to content

Commit

Permalink
chore: Build and Publish the SDK as an NPM package
Browse files Browse the repository at this point in the history
  • Loading branch information
satyajeetkolhapure authored and alainncls committed Oct 24, 2023
1 parent fff70cc commit b54ed44
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ subgraph.yaml
.latest.json
.docker

# SDK
lib

# Misc
.DS_Store
14 changes: 14 additions & 0 deletions sdk/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.graphclient
!dist/.graphclient
examples
node_modules
src
!dist/src
test
.env
.env.example
.graphclientrc.yml
.npmignore
babel-jest.config.cjs
jest.config.js
tsconfig.json
7 changes: 7 additions & 0 deletions sdk/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2023 ConsenSys Software, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 25 additions & 2 deletions sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linea-attestation-registry-sdk",
"version": "0.0.1",
"name": "@verax-attestation-registry/verax-sdk",
"version": "0.0.6",
"description": "Verax Attestation Registry SDK to interact with the subgraph and the contracts",
"keywords": [
"linea-attestation-registry",
Expand All @@ -15,8 +15,31 @@
"license": "MIT",
"author": "Consensys",
"type": "module",
"files": [
"lib/**/*"
],
"types": "./lib/cjs/types/index.d.ts",
"main": "./lib/cjs/index.js",
"exports": {
".": {
"import": {
"types": "./lib/esm/types/src/VeraxSdk.d.ts",
"default": "./lib/esm/src/VeraxSdk.js"
},
"require": {
"types": "./lib/cjs/types/src/VeraxSdk.d.ts",
"default": "./lib/cjs/src/VeraxSdk.js"
}
}
},
"scripts": {
"attestation": "ts-node examples/attestation/index.ts",
"clean": "rm -rf ./lib",
"build": "pnpm run clean && pnpm run build:esm && pnpm run build:cjs",
"build:esm": "tsc -p ./tsconfig.esm.json",
"build:cjs": "tsc -p ./tsconfig.cjs.json",
"prepack": "npm run build",
"publish:public": "pnpm publish --access public --no-git-checks",
"module": "ts-node examples/module/index.ts",
"portal": "ts-node examples/portal/index.ts",
"schema": "ts-node examples/schema/index.ts",
Expand Down
21 changes: 16 additions & 5 deletions sdk/src/VeraxSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ import AttestationDataMapper from "./dataMapper/AttestationDataMapper";
import SchemaDataMapper from "./dataMapper/SchemaDataMapper";
import ModuleDataMapper from "./dataMapper/ModuleDataMapper";
import PortalDataMapper from "./dataMapper/PortalDataMapper";
import { createPublicClient, createWalletClient, custom, Hex, http, PublicClient, WalletClient } from "viem";
import { Address, createPublicClient, createWalletClient, custom, Hex, http, PublicClient, WalletClient } from "viem";
import UtilsDataMapper from "./dataMapper/UtilsDataMapper";
import { privateKeyToAccount } from "viem/accounts";
import dotenv from "dotenv";
import { PrivateKeyAccount, privateKeyToAccount } from "viem/accounts";
import { Conf } from "./types";
import { SDKMode } from "./utils/constants";

dotenv.config({ path: "./.env" });
let account: PrivateKeyAccount | Address;

if (typeof window === "undefined") {
import("dotenv").then((dotenv) => {
dotenv.config({ path: "./.env" });
account = privateKeyToAccount(process.env.PRIVATE_KEY as Hex);
});
} else {
window.ethereum.request({ method: "eth_requestAccounts" }).then((result: Address[]) => {
account = result[0];
});
}

export default class VeraxSdk {
static DEFAULT_LINEA_MAINNET: Conf = {
Expand Down Expand Up @@ -62,11 +72,12 @@ export default class VeraxSdk {
conf.mode === SDKMode.BACKEND
? createWalletClient({
chain: conf.chain,
account: privateKeyToAccount(process.env.PRIVATE_KEY as Hex),
account,
transport: http(),
})
: createWalletClient({
chain: conf.chain,
account,
transport: custom(window.ethereum),
});

Expand Down
12 changes: 12 additions & 0 deletions sdk/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": ["ES6", "DOM"],
"target": "ES6",
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "./lib/cjs",
"declarationDir": "./lib/cjs/types"
},
"include": ["src/**/*.ts", ".graphclient/**/*.ts"]
}
11 changes: 11 additions & 0 deletions sdk/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"module": "ESNext",
"moduleResolution": "Bundler",
"outDir": "./lib/esm",
"declarationDir": "./lib/esm/types"
},
"include": ["src/**/*.ts", ".graphclient/**/*.ts"]
}
15 changes: 12 additions & 3 deletions sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"target": "ESNext"
"strict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"checkJs": true,
"allowJs": true,
"declaration": true,
"declarationMap": true,
"allowSyntheticDefaultImports": true,
"outDir": "./lib",
"sourceMap": true,
"noEmit": false
},
"ts-node": {
"esm": true,
Expand Down

0 comments on commit b54ed44

Please sign in to comment.