Skip to content

@keymaster/connect / KeymasterConnectClient

Class: KeymasterConnectClient ​

Official browser client for Keymaster Connect V1.

One client owns one reusable Session Window. It validates both the exact message origin and the source window, correlates concurrent requests by id, supports protocol cancellation through AbortSignal, and keeps persistent Connect sessions separate from the window transport lifecycle.

Examples ​

Direct popup login

ts
const keymaster = new KeymasterConnectClient({
  targetOrigin: keymasterDeploymentOrigin
});

const session = await keymaster.login({
  text: "Sign in to Example",
  claims: ["profile.name"]
});

appView launch

ts
const keymaster = new KeymasterConnectClient({
  targetOrigin: sessionWindowOrigin,
  mode: "appView"
});

await keymaster.connect();
const session = await keymaster.launch({ launchToken, appIdentity });

Connect ​

Create, restore, revoke, or launch a persistent Connect session.

login() ​

login(params, options?): Promise<ConnectLoginResult>

Calls connect.login to create a persistent Connect session.

Parameters ​

params ​

ConnectLoginParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<ConnectLoginResult>


resume() ​

resume(connectSessionId, options?): Promise<ConnectResumeResult>

Calls connect.resume to restore the unlock runtime for a persistent session.

Parameters ​

connectSessionId ​

string

options? ​

KeymasterRequestOptions

Returns ​

Promise<ConnectResumeResult>


logout() ​

logout(connectSessionId, options?): Promise<ConnectLogoutResult>

Calls connect.logout to revoke a persistent Connect session.

Parameters ​

connectSessionId ​

string

options? ​

KeymasterRequestOptions

Returns ​

Promise<ConnectLogoutResult>


launch() ​

launch(params, options?): Promise<ConnectLaunchResult>

Calls connect.launch to consume the one-time launch token of an appView session.

Parameters ​

params ​

ConnectLaunchParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<ConnectLaunchResult>

Identity ​

Read signed identity claims or sign an application intent.

identityGet() ​

identityGet(params, options?): Promise<IdentityGetResult>

Calls identity.get to return signed identity claims for the session owner.

Parameters ​

params ​

IdentityGetParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<IdentityGetResult>


intentSign() ​

intentSign(params, options?): Promise<IntentSignResult>

Calls intent.sign to sign caller-provided bytes with a human-readable intent.

Parameters ​

params ​

IntentSignParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<IntentSignResult>

Cipher ​

Encrypt and decrypt origin-bound application data.

cipherEncrypt() ​

cipherEncrypt(params, options?): Promise<CipherEncryptResult>

Calls cipher.encrypt to encrypt origin-bound application data.

Parameters ​

params ​

CipherEncryptParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<CipherEncryptResult>


cipherDecrypt() ​

cipherDecrypt(params, options?): Promise<CipherDecryptResult>

Calls cipher.decrypt to decrypt data previously returned by cipher.encrypt.

Parameters ​

params ​

CipherDecryptParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<CipherDecryptResult>

Transfer ​

Request a controlled BSV transfer.

p2pkhTransfer() ​

p2pkhTransfer(params, options?): Promise<P2pkhTransferResult>

Calls p2pkh.transfer to request a controlled mainnet BSV transfer.

Parameters ​

params ​

P2pkhTransferParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<P2pkhTransferResult>

Channel ​

Publish JSON content and manage exact-channel subscriptions. Incoming messages arrive as channel.message_received events.

channelPublish() ​

channelPublish(params, options?): Promise<ChannelPublishResult>

发布到任意精确频道;owner、公钥签名和消息编号由 Keymaster 生成。

Parameters ​

params ​

ChannelPublishParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<ChannelPublishResult>


channelSubscriptionSet() ​

channelSubscriptionSet(params, options?): Promise<ChannelSubscriptionSetResult>

替换当前 Connect caller 的精确频道订阅集合;传空数组表示释放。

Parameters ​

params ​

ChannelSubscriptionSetParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<ChannelSubscriptionSetResult>

Storage ​

Manage app-scoped directories, objects, and multipart uploads.

storageList() ​

storageList(params, options?): Promise<StorageListResult>

Calls storage.list to list paths in the verified application's namespace.

Parameters ​

params ​

StorageListParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<StorageListResult>


storageDirectoryCreate() ​

storageDirectoryCreate(params, options?): Promise<StorageDirectoryResult>

Calls storage.directory.create to create an app-scoped directory.

Parameters ​

params ​

StorageDirectoryParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<StorageDirectoryResult>


storageDirectoryDelete() ​

storageDirectoryDelete(params, options?): Promise<StorageDirectoryResult>

Calls storage.directory.delete to delete an app-scoped directory.

Parameters ​

params ​

StorageDirectoryParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<StorageDirectoryResult>


storagePut() ​

storagePut(params, options?): Promise<StoragePutResult>

Calls storage.put to write an app-scoped object.

Parameters ​

params ​

StoragePutParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<StoragePutResult>


storageGet() ​

storageGet(params, options?): Promise<StorageGetResult>

Calls storage.get to read an app-scoped object.

Parameters ​

params ​

StorageGetParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<StorageGetResult>


storageDelete() ​

storageDelete(params, options?): Promise<StorageDeleteResult>

Calls storage.delete to delete an app-scoped object.

Parameters ​

params ​

StorageDeleteParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<StorageDeleteResult>

Transport ​

Manage the Session Window and send lower-level protocol requests.

state ​

Get Signature ​

get state(): KeymasterConnectState

Current browser transport state.

Returns ​

KeymasterConnectState


connect() ​

connect(): Promise<void>

Establishes the browser transport.

Popup mode opens the Session Window and waits for ready. appView mode adopts window.opener, installs the listener, and sends the child ready message without ever opening a fallback popup.

Returns ​

Promise<void>


request() ​

request<M>(method, params, options?): Promise<MethodResult<M>>

Sends any public Connect method with compile-time parameter and result inference.

Type Parameters ​

M ​

M extends ProtocolMethod

Parameters ​

method ​

M

params ​

MethodParams<M>

options? ​

KeymasterRequestOptions = {}

Returns ​

Promise<MethodResult<M>>


cancel() ​

cancel(requestId, reason?): boolean

Cancels a locally pending request. Keymaster only cancels work that has not entered execution; cancellation is therefore best-effort remotely.

Parameters ​

requestId ​

string

reason? ​

unknown = ...

Returns ​

boolean


close() ​

close(): void

Tears down the local transport. This does not revoke persistent Connect sessions; call logout before closing when revocation is required.

Returns ​

void

Constructors ​

Constructor ​

new KeymasterConnectClient(options): KeymasterConnectClient

Parameters ​

options ​

KeymasterConnectOptions

Returns ​

KeymasterConnectClient

MSFile ​

msfileStat() ​

msfileStat(params, options?): Promise<MsFileStatResult>

Calls msfile.stat to query every enabled MSFile supplier for a seed hash. The caller selects supplier/hash only; price policy stays inside Keymaster.

Parameters ​

params ​

MsFileStatParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<MsFileStatResult>


msfileReadSeed() ​

msfileReadSeed(params, options?): Promise<MsFileReadResult>

Calls msfile.seed.read to buy and read a MasterSeed by hash. There is no price parameter: Keymaster resolves the amount from its settings or asks the user for approval when needed.

Parameters ​

params ​

MsFileSeedReadParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<MsFileReadResult>


msfileReadBlock() ​

msfileReadBlock(params, options?): Promise<MsFileReadResult>

Calls msfile.block.read to buy and read a single file block by hash. Like msfileReadSeed, no caller-supplied price is accepted.

Parameters ​

params ​

MsFileBlockReadParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<MsFileReadResult>

Price ​

Read the Keymaster display price (amount + unit) once, or subscribe to price.changed pushes. The price is display-only reference data.

priceGet() ​

priceGet(params, options?): Promise<PriceValue>

一次读取 Keymaster 当前的 BSV 展示价格(金额 + 单位)。

未就绪(未配置 / 未收到快照 / 订阅出错)时返回 amount: "0.00"; 价格只作显示参考,不用于业务判断。

Parameters ​

params ​

PriceGetParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<PriceValue>


priceSubscribe() ​

priceSubscribe(params, options?): Promise<PriceSubscriptionResult>

订阅 price.changed 推送;订阅前不会收到价格事件。

Parameters ​

params ​

PriceSubscribeParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<PriceSubscriptionResult>


priceUnsubscribe() ​

priceUnsubscribe(params, options?): Promise<PriceSubscriptionResult>

取消当前会话的 price.changed 推送。

Parameters ​

params ​

PriceSubscribeParams

options? ​

KeymasterRequestOptions

Returns ​

Promise<PriceSubscriptionResult>

使用能力,不托管私钥。