@moralisweb3/sol-utils
Advanced tools
Comparing version 2.0.3 to 2.1.0
import { MoralisData, MoralisDataFormatted } from '@moralisweb3/core'; | ||
/** | ||
* Valid input for a new SolAddress instance. | ||
* This can be an existing SolAddress or a valid address string. | ||
* | ||
* @example "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM" | ||
* @example SolAddress.create("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM") | ||
*/ | ||
export declare type SolAddressish = SolAddress | string; | ||
/** | ||
* A representation of an address on the Solana network. | ||
* | ||
* Use this class any time you work with an address. | ||
* | ||
* @category DataType | ||
*/ | ||
export declare class SolAddress implements MoralisData { | ||
readonly address: string; | ||
/** | ||
* Create a new instance of SolAddress from any valid address input. | ||
* | ||
* @example `const address = SolAddress.create("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM")` | ||
* @throws an error when a passed address is invalid. | ||
*/ | ||
static create(address: SolAddressish): SolAddress; | ||
private static parse; | ||
constructor(address: string); | ||
/** | ||
* Formats the address to a specific format. | ||
* Currently returns a string representing the address. | ||
* @example "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM" | ||
*/ | ||
format(): MoralisDataFormatted; | ||
equals(address: SolAddress): boolean; | ||
/** | ||
* Checks the equality of the current address with another Solana address. | ||
* @example `address.equals("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM")` | ||
* @example `address.equals(SolAddress.create("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"))` | ||
*/ | ||
equals(address: SolAddressish): boolean; | ||
/** | ||
* @returns a string representing the address. | ||
* @example "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM" | ||
*/ | ||
toString(): string; | ||
/** | ||
* @returns a string representing the address. | ||
* @example "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM" | ||
*/ | ||
toJSON(): string; | ||
} | ||
//# sourceMappingURL=SolAddress.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SolAddress = void 0; | ||
var core_1 = require("@moralisweb3/core"); | ||
var web3_js_1 = require("@solana/web3.js"); | ||
/** | ||
* A representation of an address on the Solana network. | ||
* | ||
* Use this class any time you work with an address. | ||
* | ||
* @category DataType | ||
*/ | ||
var SolAddress = /** @class */ (function () { | ||
@@ -8,2 +17,8 @@ function SolAddress(address) { | ||
} | ||
/** | ||
* Create a new instance of SolAddress from any valid address input. | ||
* | ||
* @example `const address = SolAddress.create("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM")` | ||
* @throws an error when a passed address is invalid. | ||
*/ | ||
SolAddress.create = function (address) { | ||
@@ -13,5 +28,15 @@ return address instanceof SolAddress ? address : new SolAddress(SolAddress.parse(address)); | ||
SolAddress.parse = function (address) { | ||
// TODO: add address validation | ||
if (!web3_js_1.PublicKey.isOnCurve(address)) { | ||
throw new core_1.MoralisCoreError({ | ||
code: core_1.CoreErrorCode.INVALID_ARGUMENT, | ||
message: 'Invalid Solana address provided', | ||
}); | ||
} | ||
return address; | ||
}; | ||
/** | ||
* Formats the address to a specific format. | ||
* Currently returns a string representing the address. | ||
* @example "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM" | ||
*/ | ||
SolAddress.prototype.format = function () { | ||
@@ -21,8 +46,21 @@ // TODO: add `format` argument | ||
}; | ||
/** | ||
* Checks the equality of the current address with another Solana address. | ||
* @example `address.equals("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM")` | ||
* @example `address.equals(SolAddress.create("9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"))` | ||
*/ | ||
SolAddress.prototype.equals = function (address) { | ||
return this.address === address.address; | ||
return this.address === SolAddress.create(address).address; | ||
}; | ||
/** | ||
* @returns a string representing the address. | ||
* @example "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM" | ||
*/ | ||
SolAddress.prototype.toString = function () { | ||
return this.address; | ||
}; | ||
/** | ||
* @returns a string representing the address. | ||
* @example "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM" | ||
*/ | ||
SolAddress.prototype.toJSON = function () { | ||
@@ -29,0 +67,0 @@ return this.address; |
{ | ||
"name": "@moralisweb3/sol-utils", | ||
"author": "Moralis", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
@@ -17,7 +17,4 @@ "private": false, | ||
"test:watch": "yarn run test --watch", | ||
"format": "prettier . \"**/*.+(js|ts|json)\" --write", | ||
"lint": "eslint . --ext .js,.ts,.tsx,jsx", | ||
"format:check": "prettier . \"**/*.+(js|ts|json)\" --check", | ||
"clean": "rm -rf lib && rm -rf lib.esm && rm -rf tsconfig.tsbuildinfo", | ||
"gen:types": "openapi-typescript https://solana-gateway.moralis.io/api-json/ --output src/generated/types.ts", | ||
"build": "tsc", | ||
@@ -32,4 +29,5 @@ "dev": "tsc --watch" | ||
"dependencies": { | ||
"@moralisweb3/core": "^2.0.3" | ||
"@moralisweb3/core": "^2.1.0", | ||
"@solana/web3.js": "^1.53.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24686
402
2
+ Added@solana/web3.js@^1.53.0
+ Added@babel/runtime@7.25.7(transitive)
+ Added@noble/curves@1.6.0(transitive)
+ Added@noble/hashes@1.5.0(transitive)
+ Added@solana/buffer-layout@4.0.1(transitive)
+ Added@solana/web3.js@1.95.4(transitive)
+ Added@swc/helpers@0.5.13(transitive)
+ Added@types/connect@3.4.38(transitive)
+ Added@types/node@12.20.55(transitive)
+ Added@types/uuid@8.3.4(transitive)
+ Added@types/ws@7.4.78.5.12(transitive)
+ AddedJSONStream@1.3.5(transitive)
+ Addedagentkeepalive@4.5.0(transitive)
+ Addedbase-x@3.0.10(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbigint-buffer@1.1.5(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedbn.js@5.2.1(transitive)
+ Addedborsh@0.7.0(transitive)
+ Addedbs58@4.0.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedbufferutil@4.0.8(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addeddelay@5.0.0(transitive)
+ Addedes6-promise@4.2.8(transitive)
+ Addedes6-promisify@5.0.0(transitive)
+ Addedeventemitter3@5.0.1(transitive)
+ Addedeyes@0.1.8(transitive)
+ Addedfast-stable-stringify@1.0.0(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedhumanize-ms@1.2.1(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedisomorphic-ws@4.0.1(transitive)
+ Addedjayson@4.1.2(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsonparse@1.3.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addednode-gyp-build@4.8.2(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedrpc-websockets@9.0.4(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsuperstruct@2.0.2(transitive)
+ Addedtext-encoding-utf-8@1.0.2(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedutf-8-validate@5.0.10(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedws@7.5.108.18.0(transitive)
Updated@moralisweb3/core@^2.1.0