@solana-mobile/safari-extension-walletlib-js
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,5 +0,2 @@ | ||
import { Base58EncodedAddress, JSONObject } from './types'; | ||
export type NativeGetAccountsParams = { | ||
extra_data?: Record<string, JSONObject>; | ||
}; | ||
import { Base58EncodedAddress } from './types'; | ||
export type NativeGetAccountsResult = { | ||
@@ -9,2 +6,2 @@ addresses: Base58EncodedAddress[]; | ||
export declare const NATIVE_GET_ACCOUNTS_RPC_METHOD = "NATIVE_GET_ACCOUNTS_METHOD"; | ||
export declare function sendNativeGetAccountsRequest({ extra_data, }?: NativeGetAccountsParams): Promise<NativeGetAccountsResult>; | ||
export declare function sendNativeGetAccountsRequest(id?: string): Promise<NativeGetAccountsResult>; |
@@ -13,32 +13,22 @@ "use strict"; | ||
exports.sendNativeGetAccountsRequest = exports.NATIVE_GET_ACCOUNTS_RPC_METHOD = void 0; | ||
const uuid_1 = require("uuid"); | ||
const sendNativeRpcRequest_1 = require("./sendNativeRpcRequest"); | ||
const errors_1 = require("./errors"); | ||
exports.NATIVE_GET_ACCOUNTS_RPC_METHOD = 'NATIVE_GET_ACCOUNTS_METHOD'; | ||
// Basic JSON schema validation | ||
function isValidNativeGetAccountsResult(obj) { | ||
return (Array.isArray(obj.addresses) && | ||
obj.addresses.every((addr) => typeof addr === 'string')); | ||
} | ||
function sendNativeGetAccountsRequest({ extra_data = {}, } = {}) { | ||
var _a, _b; | ||
function sendNativeGetAccountsRequest(id = (0, uuid_1.v4)()) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const nativeResponse = yield (0, sendNativeRpcRequest_1.sendNativeRpcRequest)({ | ||
method: exports.NATIVE_GET_ACCOUNTS_RPC_METHOD, | ||
params: { | ||
extra_data, | ||
}, | ||
params: null, | ||
id, | ||
}); | ||
if (nativeResponse.result) { | ||
const resultObj = JSON.parse(nativeResponse.result); | ||
if (isValidNativeGetAccountsResult(resultObj)) { | ||
return resultObj; | ||
} | ||
else { | ||
throw new Error('Response does not match the NativeGetAccountsResult structure.'); | ||
} | ||
if (nativeResponse.error) { | ||
throw new errors_1.SafariExtensionWalletlibRpcError(nativeResponse.id, nativeResponse.error.code, nativeResponse.error.message); | ||
} | ||
else { | ||
throw new Error((_b = (_a = nativeResponse.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Invalid RPC Response'); | ||
if (!(nativeResponse === null || nativeResponse === void 0 ? void 0 : nativeResponse.result)) { | ||
throw new Error('Received an unexpected response format.'); | ||
} | ||
return JSON.parse(nativeResponse.result); | ||
}); | ||
} | ||
exports.sendNativeGetAccountsRequest = sendNativeGetAccountsRequest; |
@@ -1,6 +0,5 @@ | ||
import { Base64EncodedAddress, Base64EncodedPayload, Base64EncodedSignedPayload, JSONObject } from './types'; | ||
import { Base64EncodedAddress, Base64EncodedPayload, Base64EncodedSignedPayload } from './types'; | ||
export type NativeSignPayloadsParams = { | ||
address: Base64EncodedAddress; | ||
payloads: Base64EncodedPayload[]; | ||
extra_data?: Record<string, JSONObject>; | ||
}; | ||
@@ -11,2 +10,4 @@ export type NativeSignPayloadsResult = { | ||
export declare const NATIVE_SIGN_PAYLOADS_RPC_METHOD = "NATIVE_SIGN_PAYLOADS_METHOD"; | ||
export declare function sendNativeSignPayloadsRequest({ address, payloads, extra_data, }: NativeSignPayloadsParams): Promise<NativeSignPayloadsResult>; | ||
export declare function sendNativeSignPayloadsRequest({ address, payloads, id, }: NativeSignPayloadsParams & { | ||
id?: string; | ||
}): Promise<NativeSignPayloadsResult>; |
@@ -13,3 +13,5 @@ "use strict"; | ||
exports.sendNativeSignPayloadsRequest = exports.NATIVE_SIGN_PAYLOADS_RPC_METHOD = void 0; | ||
const uuid_1 = require("uuid"); | ||
const sendNativeRpcRequest_1 = require("./sendNativeRpcRequest"); | ||
const errors_1 = require("./errors"); | ||
// Basic JSON schema validation | ||
@@ -21,27 +23,21 @@ function isValidSignPayloadsResult(resultObj) { | ||
exports.NATIVE_SIGN_PAYLOADS_RPC_METHOD = 'NATIVE_SIGN_PAYLOADS_METHOD'; | ||
function sendNativeSignPayloadsRequest({ address, payloads, extra_data, }) { | ||
var _a, _b; | ||
function sendNativeSignPayloadsRequest({ address, payloads, id = (0, uuid_1.v4)(), }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const nativeResponse = yield (0, sendNativeRpcRequest_1.sendNativeRpcRequest)({ | ||
method: exports.NATIVE_SIGN_PAYLOADS_RPC_METHOD, | ||
params: { | ||
params: JSON.stringify({ | ||
address, | ||
payloads, | ||
extra_data: extra_data !== null && extra_data !== void 0 ? extra_data : {}, | ||
}, | ||
}), | ||
id, | ||
}); | ||
if (nativeResponse.result) { | ||
const resultObj = JSON.parse(nativeResponse.result); | ||
if (isValidSignPayloadsResult(resultObj)) { | ||
return resultObj; | ||
} | ||
else { | ||
throw new Error('Response does not match the NativeSignPayloadsResult structure.'); | ||
} | ||
if (nativeResponse.error) { | ||
throw new errors_1.SafariExtensionWalletlibRpcError(nativeResponse.id, nativeResponse.error.code, nativeResponse.error.message); | ||
} | ||
else { | ||
throw new Error((_b = (_a = nativeResponse.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Invalid RPC Response'); | ||
if (!(nativeResponse === null || nativeResponse === void 0 ? void 0 : nativeResponse.result)) { | ||
throw new Error('Received an unexpected response format.'); | ||
} | ||
return JSON.parse(nativeResponse.result); | ||
}); | ||
} | ||
exports.sendNativeSignPayloadsRequest = sendNativeSignPayloadsRequest; |
import { NativeRpcRequest, NativeRpcResponse } from './types'; | ||
export declare function sendNativeRpcRequest({ method, params, }: NativeRpcRequest): Promise<NativeRpcResponse>; | ||
export declare function sendNativeRpcRequest({ method, params, id, }: NativeRpcRequest): Promise<NativeRpcResponse>; |
@@ -13,14 +13,15 @@ "use strict"; | ||
exports.sendNativeRpcRequest = void 0; | ||
function sendNativeRpcRequest({ method, params, }) { | ||
function sendNativeRpcRequest({ method, params, id, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const request = { | ||
jsonrpc: '2.0', | ||
method: method, | ||
params: JSON.stringify(params), | ||
params, | ||
id, | ||
}; | ||
try { | ||
return yield browser.runtime.sendNativeMessage('id', request); | ||
return yield browser.runtime.sendNativeMessage('_', request); | ||
} | ||
catch (error) { | ||
console.error('RPC request failed:', error); | ||
throw error; | ||
throw new Error('Error sending native message'); | ||
} | ||
@@ -27,0 +28,0 @@ }); |
@@ -7,11 +7,6 @@ export type Base64EncodedAddress = string; | ||
export type Base64EncodedSignedPayload = string; | ||
export type JSONValue = string | number | boolean | null | JSONArray | JSONObject; | ||
export interface JSONArray extends Array<JSONValue> { | ||
} | ||
export interface JSONObject { | ||
[key: string]: JSONValue; | ||
} | ||
export interface NativeRpcRequest { | ||
method: string; | ||
params: JSONObject; | ||
params: string | null; | ||
id: string; | ||
} | ||
@@ -24,2 +19,3 @@ export interface NativeRpcResponse { | ||
}; | ||
id: string; | ||
} |
{ | ||
"name": "@solana-mobile/safari-extension-walletlib-js", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "The typescript portion of the Safari Extension Walletlib SDK for Solana Wallet apps.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
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
15848
15
188