near-ca
Version:
An SDK for controlling Ethereum Accounts from a Near Account.
57 lines (56 loc) • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Beta = void 0;
const utils_1 = require("./utils");
const types_1 = require("./types");
/**
* Removes the EIP-155 prefix from an address string
*
* @param eip155Address - The EIP-155 formatted address
* @returns The address without the EIP-155 prefix
*/
function stripEip155Prefix(eip155Address) {
return eip155Address.split(":").pop() ?? "";
}
/**
* Features currently under development that will be migrated into the adapter class once refined.
* These features are accessible through the adapter class as `adapter.beta.methodName(...)`
*/
class Beta {
/**
* Creates a new Beta instance
*
* @param adapter - The NearEthAdapter instance to use
*/
constructor(adapter) {
this.adapter = adapter;
}
/**
* Handles a WalletConnect session request by encoding it for NEAR
*
* @param request - The WalletConnect session request
* @returns The encoded request for NEAR
* @throws Error if the sign method is not supported
*/
async handleSessionRequest(request) {
const { chainId, request: { method, params }, } = request.params;
if (!(0, types_1.isSignMethod)(method)) {
throw new Error(`Unsupported sign method ${method}: Available sign methods ${types_1.signMethods}`);
}
const { evmMessage, hashToSign } = await (0, utils_1.requestRouter)({
method,
chainId: parseInt(stripEip155Prefix(chainId)),
params,
});
return {
nearPayload: await this.adapter.mpcContract.encodeSignatureRequestTx({
path: this.adapter.derivationPath,
payload: (0, utils_1.toPayload)(hashToSign),
key_version: 0,
}),
evmMessage,
hashToSign,
};
}
}
exports.Beta = Beta;