Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

naas client test #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
src
# Ignore files with sensitive environment variables
.env
.env.test
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"name": "onec-sdk",
"version": "0.1.5",
"description": "Onec Client NPM Package",
"main": "./dist/onec-client.bundle.js",
"name": "ceno-test",
"version": "0.3.1",
"description": "ceno Client NPM Package",
"main": "./dist/onec-sdk.bundle.js",
"exports": {
".": "./dist/onec-sdk.bundle.js",
"./client": "./src/client/onec-client.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --mode=development",
Expand Down
183 changes: 183 additions & 0 deletions src/client/onec-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
var constants = require("../constants");
var axios = require('axios');

const ONEC_AUTH_USERS_BASE_URL = constants.ONEC_NAAS_BASE_URL

class naas {
constructor(api_key) {
this.api_key = api_key;
}

async mintNFT(data) {
const url = `${ONEC_AUTH_USERS_BASE_URL}mintNFT/`
const resData = await axios.post(url, data, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async mintRefNFT(data) {
const url = `${ONEC_AUTH_USERS_BASE_URL}mintRefNFT/`
const resData = await axios.post(url, data, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async checkMintStatus(txn_tracker) {
const url = `${ONEC_AUTH_USERS_BASE_URL}checkMintStatus/${txn_tracker}/`
const resData = await axios.get(url, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async fetchTokenID(nft_id) {
const url = `${ONEC_AUTH_USERS_BASE_URL}fetchTokenId/${nft_id}/`
const resData = await axios.get(url, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async fetchRefTokenID(refnft_id) {
const url = `${ONEC_AUTH_USERS_BASE_URL}fetchRefTokenId/${refnft_id}/`
const resData = await axios.get(url, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async getTokenMetadataHash(token_id) {
const url = `${ONEC_AUTH_USERS_BASE_URL}getTokenMetadataHash/${token_id}/`
const resData = await axios.get(url, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async getRefNFTs(parent_id) {
const url = `${ONEC_AUTH_USERS_BASE_URL}getRefNFTs/${parent_id}/`
const resData = await axios.get(url, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async getIpfsFiles() {
const url = `${ONEC_AUTH_USERS_BASE_URL}ipfsFile/`
const resData = await axios.get(url, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async uploadIpfsFiles(files) {
const url = `${ONEC_AUTH_USERS_BASE_URL}ipfsFile/`
const resData = await axios.post(url, files, {
headers: {
"Content-Type": "multipart/form-data",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async getIpfsMetaData() {
const url = `${ONEC_AUTH_USERS_BASE_URL}ipfsMetaData/`
const resData = await axios.get(url, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

async uploadIpfsMetaData(data) {
const url = `${ONEC_AUTH_USERS_BASE_URL}ipfsMetaData/`
const resData = await axios.post(url, data, {
headers: {
"Content-Type": "application/json",
"NAAS-APIKEY": this.api_key
}
})
.then((response) => {
return response.data;
})

return resData
}

verifyKey() {
return this.api_key
}
}

module.exports = {
naas
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { withWalletConnect, withMetamask } from "./AuthUtils/WalletAuth";
import { withWalletConnect, withMetamask } from "./web/AuthUtils/WalletAuth";

const auth = {
withMetamask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import MetaMaskOnboarding from '@metamask/onboarding';
import WalletConnect from "@walletconnect/client";
import QRCodeModal from "@walletconnect/qrcode-modal";
import axios, { AxiosResponse, AxiosError } from 'axios';
import * as constants from "../constants"
import * as constants from "../../constants"

let ONEC_AUTH_USERS_BASE_URL = constants.ONEC_NAAS_BASE_URL;
let _mmConnector = null;
Expand Down
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module.exports = {
output: {
path: path.resolve(__dirname, 'dist'),
clean: true,
filename: 'onec-client.bundle.js',
filename: 'onec-sdk.bundle.js',
library: {
name: 'onec',
name: 'onec-sdk',
type: 'umd',
umdNamedDefine: true,
export: 'default',
Expand Down