UNPKG

@openweb3-io/waas

Version:

WaaS API client and WaaS verification library

272 lines 10.1 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WaaS = void 0; const index_1 = require("./openapi/index"); __exportStar(require("./openapi/models/all"), exports); __exportStar(require("./openapi/apis/exception"), exports); const crypto_1 = require("crypto"); const nacl = require("tweetnacl"); const VERSION = "0.2.0"; class UserAgentMiddleware { pre(context) { context.setHeaderParam("User-Agent", `WaaS-libs/${VERSION}/javascript`); return Promise.resolve(context); } post(context) { return Promise.resolve(context); } } function signEd25519(data, privateKey) { const hash = crypto_1.createHash("sha256"); hash.update(Buffer.from(data, "utf-8")); const hashBuffer = hash.digest(); const keyPair = nacl.sign.keyPair.fromSeed(Buffer.from(privateKey, "hex")); const signedData = nacl.sign.detached(hashBuffer, keyPair.secretKey); const sign = Buffer.from(signedData).toString("hex"); return sign; } class SignatureMiddleware { constructor(privateKey) { this.privateKey = privateKey; } pre(context) { var _a; const timestamp = new Date().getTime().toString(); context.setHeaderParam("x-request-time", timestamp); let source = ""; source += ((_a = context.getBody()) === null || _a === void 0 ? void 0 : _a.toString()) || ""; const url = new URL(context.getUrl()); source += url.pathname + url.search; source += timestamp; const sign = signEd25519(source, this.privateKey); context.setHeaderParam("x-signature", sign); return Promise.resolve(context); } post(context) { return Promise.resolve(context); } } class WaaS { constructor(apikey, privateKey, options = {}) { var _a; const baseUrl = (_a = options.serverUrl) !== null && _a !== void 0 ? _a : "https://api.waas.openweb3.io"; const baseServer = new index_1.ServerConfiguration(baseUrl, {}); const config = index_1.createConfiguration({ baseServer, promiseMiddleware: [new UserAgentMiddleware(), new SignatureMiddleware(privateKey)], authMethods: { ApiKeyAuth: apikey, }, }); this._configuration = config; this.Addresses = new Addresses(config); this.Chains = new Chains(config); this.Sweeps = new Sweeps(config); this.Tokens = new Tokens(config); this.Transactions = new Transactions(config); this.Wallets = new Wallets(config); this.WebhookEndpoints = new WebhookEndpoints(config); this.WebhookEvents = new WebhookEvents(config); } } exports.WaaS = WaaS; class Addresses { constructor(config) { this.api = new index_1.AddressesApi(config); } list(options) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1AddressesList(Object.assign({}, options)); }); } listByWallet(walletId, options) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WalletsListAddresses(Object.assign({ walletId }, options)); }); } validateAddresses(chainId, addresses) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1AddressesValidate({ chainId, addresses }); }); } create(walletId, createAddressRequest) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WalletsCreateAddress({ walletId, createAddressRequest }); }); } getAddress(walletId, address) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WalletsGetAddress({ walletId, address }); }); } } class Chains { constructor(config) { this.api = new index_1.ChainsApi(config); } list(options) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1ChainsList(Object.assign({}, options)); }); } retrieve(chainId) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1ChainsRetrieve({ chainId }); }); } } class Sweeps { constructor(config) { this.api = new index_1.SweepsApi(config); } sweepAddress(address, sweepAddressRequest) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1SweepsAddress({ address, sweepAddressRequest }); }); } } class Tokens { constructor(config) { this.api = new index_1.TokensApi(config); } list(options) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1TokensList(Object.assign({}, options)); }); } create(createTokenRequest) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1TokensCreate({ createTokenRequest }); }); } retrieve(tokenId) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1TokensRetrieve({ tokenId }); }); } update(tokenId, updateTokenRequest) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1TokensUpdate({ tokenId, updateTokenRequest }); }); } } class Transactions { constructor(config) { this.api = new index_1.TransactionsApi(config); } list(options) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1TransactionsList(Object.assign({}, options)); }); } estimateFee(estimateFeeRequest) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1TransactionsEstimateFee({ estimateFeeRequest }); }); } transferToken(createTransferRequest) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1TransactionsTransfer({ createTransferRequest }); }); } getTransaction(transactionId) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1TransactionsRetrieve({ transactionId }); }); } signMessage(signMessageRequest) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1TransactionsSignMessage({ signMessageRequest }); }); } } class Wallets { constructor(config) { this.api = new index_1.WalletsApi(config); } list(options) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WalletsList(Object.assign({}, options)); }); } create(createWalletRequest) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WalletsCreate({ createWalletRequest }); }); } delete(walletId) { return __awaiter(this, void 0, void 0, function* () { yield this.api.v1WalletsDelete({ walletId }); }); } get(walletId) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WalletsRetrieve({ walletId }); }); } update(walletId, updateWalletRequest) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WalletsUpdate({ walletId, updateWalletRequest }); }); } } class WebhookEndpoints { constructor(config) { this.api = new index_1.WebhookEndpointsApi(config); } list(options) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WebhooksEndpointList(Object.assign({}, options)); }); } create(createEndpoint) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WebhooksEndpointCreate({ createEndpoint }); }); } delete(endpointId) { return __awaiter(this, void 0, void 0, function* () { yield this.api.v1WebhooksEndpointDelete({ endpointId }); }); } get(endpointId) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WebhooksEndpointRetrieve({ endpointId }); }); } update(endpointId, updateEndpoint) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WebhooksEndpointUpdate({ endpointId, updateEndpoint }); }); } } class WebhookEvents { constructor(config) { this.api = new index_1.WebhookEventsApi(config); } list(options) { return __awaiter(this, void 0, void 0, function* () { return yield this.api.v1WebhooksEventsList(Object.assign({}, options)); }); } } //# sourceMappingURL=index.js.map