Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect & Multisig #521

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions client/HubApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ import {
SetupSwapRequest,
SetupSwapResult,
RefundSwapRequest,
SignMultisigTransactionRequest,
PartialSignature,
SignStakingRequest,
ConnectAccountRequest,
ConnectedAccount,
} from './PublicRequestTypes';

export default class HubApi<
Expand Down Expand Up @@ -215,6 +219,20 @@ export default class HubApi<
return this._request(requestBehavior, RequestType.REFUND_SWAP, [request]);
}

public signMultisigTransaction<B extends BehaviorType = DB>(
request: Promise<SignMultisigTransactionRequest> | SignMultisigTransactionRequest,
requestBehavior: RequestBehavior<B> = this._defaultBehavior as any,
): Promise<B extends BehaviorType.REDIRECT ? void : PartialSignature> {
return this._request(requestBehavior, RequestType.SIGN_MULTISIG_TRANSACTION, [request]);
}

public connectAccount<B extends BehaviorType = DB>(
request: Promise<ConnectAccountRequest> | ConnectAccountRequest,
requestBehavior: RequestBehavior<B> = this._defaultBehavior as any,
): Promise<B extends BehaviorType.REDIRECT ? void : ConnectedAccount> {
return this._request(requestBehavior, RequestType.CONNECT_ACCOUNT, [request]);
}

/**
* Account Management
*
Expand Down
74 changes: 72 additions & 2 deletions client/PublicRequestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum RequestType {
CHECKOUT = 'checkout',
SIGN_MESSAGE = 'sign-message',
SIGN_TRANSACTION = 'sign-transaction',
SIGN_MULTISIG_TRANSACTION = 'sign-multisig-transaction',
SIGN_STAKING = 'sign-staking',
ONBOARD = 'onboard',
SIGNUP = 'signup',
Expand All @@ -37,6 +38,7 @@ export enum RequestType {
ACTIVATE_POLYGON = 'activate-polygon',
SETUP_SWAP = 'setup-swap',
REFUND_SWAP = 'refund-swap',
CONNECT_ACCOUNT = 'connect-account',
}

export type Bytes = Uint8Array | string;
Expand Down Expand Up @@ -250,6 +252,43 @@ export interface SignedTransaction {
};
}

export interface EncryptionKeyParams {
kdf: string;
iterations: number;
keySize: number;
}

export interface MultisigInfo {
publicKeys: Bytes[];
signers: Array<{
publicKey: Bytes;
commitments: Bytes[];
}>;
secrets: Bytes[] | {
encrypted: Bytes[];
keyParams: EncryptionKeyParams;
};
userName?: string;
}

export interface SignMultisigTransactionRequest extends BasicRequest {
signer: string; // Address

sender: string;
senderType?: Nimiq.AccountType;
senderLabel: string;
recipient: string;
recipientType?: Nimiq.AccountType;
recipientLabel?: string;
value: number;
fee?: number;
extraData?: Bytes;
flags?: number;
validityStartHeight: number; // FIXME To be made optional when hub has its own network

multisigConfig: MultisigInfo;
}

export interface NimiqHtlcCreationInstructions {
type: 'NIM';
sender: string; // My address, must be redeem address of HTLC, or if contract, its owner must be redeem address
Expand Down Expand Up @@ -469,6 +508,8 @@ export interface SignedMessage {
signature: Uint8Array;
}

export type PartialSignature = SignedMessage;

export interface Address {
address: string; // Userfriendly address
label: string;
Expand Down Expand Up @@ -587,6 +628,29 @@ export interface ManageCashlinkRequest extends BasicRequest {
cashlinkAddress: string;
}

export interface ConnectAccountRequest extends BasicRequest {
appLogoUrl: string;
permissions: RequestType[];
requestedKeyPaths: string[];
challenge: string;
}

export interface ConnectedAccount {
signatures: SignedMessage[];
encryptionKey: {
format: 'spki',
keyData: Uint8Array,
algorithm: { name: string, hash: string },
keyUsages: ['encrypt'],
keyParams: EncryptionKeyParams,
};
account: {
label: string;
type: string;
// permissions: RequestType[];
};
}

/**
* Bitcoin
*/
Expand Down Expand Up @@ -670,6 +734,7 @@ export interface SignedPolygonTransaction {
}

export type RpcRequest = SignTransactionRequest
| SignMultisigTransactionRequest
| SignStakingRequest
| CreateCashlinkRequest
| ManageCashlinkRequest
Expand All @@ -685,10 +750,12 @@ export type RpcRequest = SignTransactionRequest
| AddBtcAddressesRequest
| SignPolygonTransactionRequest
| SetupSwapRequest
| RefundSwapRequest;
| RefundSwapRequest
| ConnectAccountRequest;

export type RpcResult = SignedTransaction
| SignedTransaction[]
| PartialSignature
| Account
| Account[]
| SimpleResult
Expand All @@ -701,7 +768,8 @@ export type RpcResult = SignedTransaction
| SignedBtcTransaction
| AddBtcAddressesResult
| SignedPolygonTransaction
| SetupSwapResult;
| SetupSwapResult
| ConnectedAccount;

export type ResultByRequestType<T> =
T extends RequestType.RENAME ? Account :
Expand All @@ -711,6 +779,7 @@ export type ResultByRequestType<T> =
T extends RequestType.CHOOSE_ADDRESS ? ChooseAddressResult :
T extends RequestType.ADD_ADDRESS ? Address :
T extends RequestType.SIGN_TRANSACTION ? SignedTransaction :
T extends RequestType.SIGN_MULTISIG_TRANSACTION ? PartialSignature :
T extends RequestType.SIGN_STAKING ? SignedTransaction[] :
T extends RequestType.CHECKOUT ? SignedTransaction | SimpleResult :
T extends RequestType.SIGN_MESSAGE ? SignedMessage :
Expand All @@ -723,4 +792,5 @@ export type ResultByRequestType<T> =
T extends RequestType.ACTIVATE_POLYGON ? Account :
T extends RequestType.ADD_BTC_ADDRESSES ? AddBtcAddressesResult :
T extends RequestType.SETUP_SWAP ? SetupSwapResult :
T extends RequestType.CONNECT_ACCOUNT ? ConnectedAccount :
never;
8 changes: 8 additions & 0 deletions client/dist/HubApi.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ var RequestType;
RequestType["CHECKOUT"] = "checkout";
RequestType["SIGN_MESSAGE"] = "sign-message";
RequestType["SIGN_TRANSACTION"] = "sign-transaction";
RequestType["SIGN_MULTISIG_TRANSACTION"] = "sign-multisig-transaction";
RequestType["SIGN_STAKING"] = "sign-staking";
RequestType["ONBOARD"] = "onboard";
RequestType["SIGNUP"] = "signup";
Expand All @@ -313,6 +314,7 @@ var RequestType;
RequestType["ACTIVATE_POLYGON"] = "activate-polygon";
RequestType["SETUP_SWAP"] = "setup-swap";
RequestType["REFUND_SWAP"] = "refund-swap";
RequestType["CONNECT_ACCOUNT"] = "connect-account";
})(RequestType || (RequestType = {}));
var AccountType;
(function (AccountType) {
Expand Down Expand Up @@ -438,6 +440,12 @@ class HubApi {
refundSwap(request, requestBehavior = this._defaultBehavior) {
return this._request(requestBehavior, RequestType.REFUND_SWAP, [request]);
}
signMultisigTransaction(request, requestBehavior = this._defaultBehavior) {
return this._request(requestBehavior, RequestType.SIGN_MULTISIG_TRANSACTION, [request]);
}
connectAccount(request, requestBehavior = this._defaultBehavior) {
return this._request(requestBehavior, RequestType.CONNECT_ACCOUNT, [request]);
}
/**
* Account Management
*
Expand Down
8 changes: 8 additions & 0 deletions client/dist/HubApi.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
RequestType["CHECKOUT"] = "checkout";
RequestType["SIGN_MESSAGE"] = "sign-message";
RequestType["SIGN_TRANSACTION"] = "sign-transaction";
RequestType["SIGN_MULTISIG_TRANSACTION"] = "sign-multisig-transaction";
RequestType["SIGN_STAKING"] = "sign-staking";
RequestType["ONBOARD"] = "onboard";
RequestType["SIGNUP"] = "signup";
Expand All @@ -316,6 +317,7 @@
RequestType["ACTIVATE_POLYGON"] = "activate-polygon";
RequestType["SETUP_SWAP"] = "setup-swap";
RequestType["REFUND_SWAP"] = "refund-swap";
RequestType["CONNECT_ACCOUNT"] = "connect-account";
})(RequestType || (RequestType = {}));
var AccountType;
(function (AccountType) {
Expand Down Expand Up @@ -441,6 +443,12 @@
refundSwap(request, requestBehavior = this._defaultBehavior) {
return this._request(requestBehavior, RequestType.REFUND_SWAP, [request]);
}
signMultisigTransaction(request, requestBehavior = this._defaultBehavior) {
return this._request(requestBehavior, RequestType.SIGN_MULTISIG_TRANSACTION, [request]);
}
connectAccount(request, requestBehavior = this._defaultBehavior) {
return this._request(requestBehavior, RequestType.CONNECT_ACCOUNT, [request]);
}
/**
* Account Management
*
Expand Down
4 changes: 3 additions & 1 deletion client/dist/src/HubApi.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PopupRequestBehavior, RequestBehavior, RedirectRequestBehavior, BehaviorType } from './RequestBehavior';
import { AccountType, RequestType, BasicRequest, SimpleRequest, OnboardRequest, ChooseAddressRequest, ChooseAddressResult, CheckoutRequest, SignTransactionRequest, RenameRequest, SignMessageRequest, ExportRequest, ResultByRequestType, Account, Address, SignedTransaction, SimpleResult, ExportResult, SignedMessage, CreateCashlinkRequest, ManageCashlinkRequest, SignBtcTransactionRequest, SignedBtcTransaction, AddBtcAddressesRequest, AddBtcAddressesResult, SignPolygonTransactionRequest, SignedPolygonTransaction, Cashlink, CashlinkState, CashlinkTheme, Currency, PaymentType, PaymentState, SetupSwapRequest, SetupSwapResult, RefundSwapRequest, SignStakingRequest } from './PublicRequestTypes';
import { AccountType, RequestType, BasicRequest, SimpleRequest, OnboardRequest, ChooseAddressRequest, ChooseAddressResult, CheckoutRequest, SignTransactionRequest, RenameRequest, SignMessageRequest, ExportRequest, ResultByRequestType, Account, Address, SignedTransaction, SimpleResult, ExportResult, SignedMessage, CreateCashlinkRequest, ManageCashlinkRequest, SignBtcTransactionRequest, SignedBtcTransaction, AddBtcAddressesRequest, AddBtcAddressesResult, SignPolygonTransactionRequest, SignedPolygonTransaction, Cashlink, CashlinkState, CashlinkTheme, Currency, PaymentType, PaymentState, SetupSwapRequest, SetupSwapResult, RefundSwapRequest, SignMultisigTransactionRequest, PartialSignature, SignStakingRequest, ConnectAccountRequest, ConnectedAccount } from './PublicRequestTypes';
export default class HubApi<DB extends BehaviorType = BehaviorType.POPUP, IB extends BehaviorType = BehaviorType.IFRAME> {
static readonly BehaviorType: typeof BehaviorType;
static readonly RequestType: typeof RequestType;
Expand Down Expand Up @@ -39,6 +39,8 @@ export default class HubApi<DB extends BehaviorType = BehaviorType.POPUP, IB ext
signPolygonTransaction<B extends BehaviorType = DB>(request: Promise<SignPolygonTransactionRequest> | SignPolygonTransactionRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : SignedPolygonTransaction>;
setupSwap<B extends BehaviorType = DB>(request: Promise<SetupSwapRequest> | SetupSwapRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : SetupSwapResult>;
refundSwap<B extends BehaviorType = DB>(request: Promise<RefundSwapRequest> | RefundSwapRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : SignedTransaction | SignedBtcTransaction | SignedPolygonTransaction>;
signMultisigTransaction<B extends BehaviorType = DB>(request: Promise<SignMultisigTransactionRequest> | SignMultisigTransactionRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : PartialSignature>;
connectAccount<B extends BehaviorType = DB>(request: Promise<ConnectAccountRequest> | ConnectAccountRequest, requestBehavior?: RequestBehavior<B>): Promise<B extends BehaviorType.REDIRECT ? void : ConnectedAccount>;
/**
* Account Management
*
Expand Down
66 changes: 62 additions & 4 deletions client/dist/src/PublicRequestTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export declare enum RequestType {
CHECKOUT = "checkout",
SIGN_MESSAGE = "sign-message",
SIGN_TRANSACTION = "sign-transaction",
SIGN_MULTISIG_TRANSACTION = "sign-multisig-transaction",
SIGN_STAKING = "sign-staking",
ONBOARD = "onboard",
SIGNUP = "signup",
Expand All @@ -27,7 +28,8 @@ export declare enum RequestType {
ACTIVATE_BITCOIN = "activate-bitcoin",
ACTIVATE_POLYGON = "activate-polygon",
SETUP_SWAP = "setup-swap",
REFUND_SWAP = "refund-swap"
REFUND_SWAP = "refund-swap",
CONNECT_ACCOUNT = "connect-account"
}
export declare type Bytes = Uint8Array | string;
export declare enum AccountType {
Expand Down Expand Up @@ -203,6 +205,38 @@ export interface SignedTransaction {
proof: Uint8Array;
};
}
export interface EncryptionKeyParams {
kdf: string;
iterations: number;
keySize: number;
}
export interface MultisigInfo {
publicKeys: Bytes[];
signers: Array<{
publicKey: Bytes;
commitments: Bytes[];
}>;
secrets: Bytes[] | {
encrypted: Bytes[];
keyParams: EncryptionKeyParams;
};
userName?: string;
}
export interface SignMultisigTransactionRequest extends BasicRequest {
signer: string;
sender: string;
senderType?: Nimiq.AccountType;
senderLabel: string;
recipient: string;
recipientType?: Nimiq.AccountType;
recipientLabel?: string;
value: number;
fee?: number;
extraData?: Bytes;
flags?: number;
validityStartHeight: number;
multisigConfig: MultisigInfo;
}
export interface NimiqHtlcCreationInstructions {
type: 'NIM';
sender: string;
Expand Down Expand Up @@ -384,6 +418,7 @@ export interface SignedMessage {
signerPublicKey: Uint8Array;
signature: Uint8Array;
}
export declare type PartialSignature = SignedMessage;
export interface Address {
address: string;
label: string;
Expand Down Expand Up @@ -481,6 +516,29 @@ export declare type CreateCashlinkRequest = BasicRequest & {
export interface ManageCashlinkRequest extends BasicRequest {
cashlinkAddress: string;
}
export interface ConnectAccountRequest extends BasicRequest {
appLogoUrl: string;
permissions: RequestType[];
requestedKeyPaths: string[];
challenge: string;
}
export interface ConnectedAccount {
signatures: SignedMessage[];
encryptionKey: {
format: 'spki';
keyData: Uint8Array;
algorithm: {
name: string;
hash: string;
};
keyUsages: ['encrypt'];
keyParams: EncryptionKeyParams;
};
account: {
label: string;
type: string;
};
}
/**
* Bitcoin
*/
Expand Down Expand Up @@ -554,6 +612,6 @@ export interface SignedPolygonTransaction {
message: Record<string, any>;
signature: string;
}
export declare type RpcRequest = SignTransactionRequest | SignStakingRequest | CreateCashlinkRequest | ManageCashlinkRequest | CheckoutRequest | BasicRequest | SimpleRequest | ChooseAddressRequest | OnboardRequest | RenameRequest | SignMessageRequest | ExportRequest | SignBtcTransactionRequest | AddBtcAddressesRequest | SignPolygonTransactionRequest | SetupSwapRequest | RefundSwapRequest;
export declare type RpcResult = SignedTransaction | SignedTransaction[] | Account | Account[] | SimpleResult | ChooseAddressResult | Address | Cashlink | Cashlink[] | SignedMessage | ExportResult | SignedBtcTransaction | AddBtcAddressesResult | SignedPolygonTransaction | SetupSwapResult;
export declare type ResultByRequestType<T> = T extends RequestType.RENAME ? Account : T extends RequestType.ONBOARD | RequestType.SIGNUP | RequestType.LOGIN | RequestType.MIGRATE | RequestType.LIST ? Account[] : T extends RequestType.LIST_CASHLINKS ? Cashlink[] : T extends RequestType.CHOOSE_ADDRESS ? ChooseAddressResult : T extends RequestType.ADD_ADDRESS ? Address : T extends RequestType.SIGN_TRANSACTION ? SignedTransaction : T extends RequestType.SIGN_STAKING ? SignedTransaction[] : T extends RequestType.CHECKOUT ? SignedTransaction | SimpleResult : T extends RequestType.SIGN_MESSAGE ? SignedMessage : T extends RequestType.LOGOUT | RequestType.CHANGE_PASSWORD ? SimpleResult : T extends RequestType.EXPORT ? ExportResult : T extends RequestType.CREATE_CASHLINK | RequestType.MANAGE_CASHLINK ? Cashlink : T extends RequestType.SIGN_BTC_TRANSACTION ? SignedBtcTransaction : T extends RequestType.SIGN_POLYGON_TRANSACTION ? SignedPolygonTransaction : T extends RequestType.ACTIVATE_BITCOIN ? Account : T extends RequestType.ACTIVATE_POLYGON ? Account : T extends RequestType.ADD_BTC_ADDRESSES ? AddBtcAddressesResult : T extends RequestType.SETUP_SWAP ? SetupSwapResult : never;
export declare type RpcRequest = SignTransactionRequest | SignMultisigTransactionRequest | SignStakingRequest | CreateCashlinkRequest | ManageCashlinkRequest | CheckoutRequest | BasicRequest | SimpleRequest | ChooseAddressRequest | OnboardRequest | RenameRequest | SignMessageRequest | ExportRequest | SignBtcTransactionRequest | AddBtcAddressesRequest | SignPolygonTransactionRequest | SetupSwapRequest | RefundSwapRequest | ConnectAccountRequest;
export declare type RpcResult = SignedTransaction | SignedTransaction[] | PartialSignature | Account | Account[] | SimpleResult | ChooseAddressResult | Address | Cashlink | Cashlink[] | SignedMessage | ExportResult | SignedBtcTransaction | AddBtcAddressesResult | SignedPolygonTransaction | SetupSwapResult | ConnectedAccount;
export declare type ResultByRequestType<T> = T extends RequestType.RENAME ? Account : T extends RequestType.ONBOARD | RequestType.SIGNUP | RequestType.LOGIN | RequestType.MIGRATE | RequestType.LIST ? Account[] : T extends RequestType.LIST_CASHLINKS ? Cashlink[] : T extends RequestType.CHOOSE_ADDRESS ? ChooseAddressResult : T extends RequestType.ADD_ADDRESS ? Address : T extends RequestType.SIGN_TRANSACTION ? SignedTransaction : T extends RequestType.SIGN_MULTISIG_TRANSACTION ? PartialSignature : T extends RequestType.SIGN_STAKING ? SignedTransaction[] : T extends RequestType.CHECKOUT ? SignedTransaction | SimpleResult : T extends RequestType.SIGN_MESSAGE ? SignedMessage : T extends RequestType.LOGOUT | RequestType.CHANGE_PASSWORD ? SimpleResult : T extends RequestType.EXPORT ? ExportResult : T extends RequestType.CREATE_CASHLINK | RequestType.MANAGE_CASHLINK ? Cashlink : T extends RequestType.SIGN_BTC_TRANSACTION ? SignedBtcTransaction : T extends RequestType.SIGN_POLYGON_TRANSACTION ? SignedPolygonTransaction : T extends RequestType.ACTIVATE_BITCOIN ? Account : T extends RequestType.ACTIVATE_POLYGON ? Account : T extends RequestType.ADD_BTC_ADDRESSES ? AddBtcAddressesResult : T extends RequestType.SETUP_SWAP ? SetupSwapResult : T extends RequestType.CONNECT_ACCOUNT ? ConnectedAccount : never;
2 changes: 1 addition & 1 deletion client/dist/standalone/HubApi.standalone.es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/standalone/HubApi.standalone.umd.js

Large diffs are not rendered by default.

Loading
Loading