@idos-network/kwil-infra 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +1 -46
- package/dist/actions/index.d.mts +2 -2
- package/dist/actions/index.mjs +1 -1
- package/dist/actions/index.mjs.map +1 -1
- package/dist/{index-Dwonqvwu.d.mts → index-Dc_rffi1.d.mts} +119 -52
- package/dist/index-Dc_rffi1.d.mts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/signature-verification/index.d.mts +1 -1
- package/package.json +2 -2
- package/src/actions/actions.test.ts +5 -3
- package/src/actions/actions.ts +313 -23
- package/src/create-kgw-authenticated-fetch.test.ts +46 -26
- package/src/create-kgw-authenticated-fetch.ts +14 -18
- package/src/create-kwil-client.test.ts +40 -0
- package/src/create-kwil-client.ts +25 -0
- package/src/create-kwil-signer.test.ts +2 -67
- package/src/create-kwil-signer.ts +2 -27
- package/src/index.ts +0 -1
- package/dist/index-Dwonqvwu.d.mts.map +0 -1
- package/src/mm-token/create-mm-token-kwil-signer.test.ts +0 -132
- package/src/mm-token/create-mm-token-kwil-signer.ts +0 -161
|
@@ -43,6 +43,16 @@ type AllKwilExecuteAction = { [Name in ActionName]: AllKwilCallAction[Name] & {
|
|
|
43
43
|
description: string;
|
|
44
44
|
}; };
|
|
45
45
|
type KwilExecuteActionRequestParams = AllKwilExecuteAction[ActionName];
|
|
46
|
+
/**
|
|
47
|
+
* A view action ran but failed (its `error()` or a runtime error). kwild reports that in the
|
|
48
|
+
* call response's `error` field, not as an HTTP/RPC error, so it is only thrown when
|
|
49
|
+
* `KwilActionClient.throwOnCallError` is set.
|
|
50
|
+
*/
|
|
51
|
+
declare class KwilCallError extends Error {
|
|
52
|
+
readonly actionName: string;
|
|
53
|
+
readonly name = "KwilCallError";
|
|
54
|
+
constructor(actionName: string, message: string);
|
|
55
|
+
}
|
|
46
56
|
/**
|
|
47
57
|
* A client for interacting with kwil with type-safe abstractions for `call` and `execute`.
|
|
48
58
|
* Has utility methods for creating actions and setting a signer.
|
|
@@ -50,6 +60,11 @@ type KwilExecuteActionRequestParams = AllKwilExecuteAction[ActionName];
|
|
|
50
60
|
declare class KwilActionClient {
|
|
51
61
|
#private;
|
|
52
62
|
signer?: KwilSigner;
|
|
63
|
+
/**
|
|
64
|
+
* When true, `call` throws `KwilCallError` if the view action reports an error. When false
|
|
65
|
+
* (default) such a call resolves to its (empty) result, as it always has.
|
|
66
|
+
*/
|
|
67
|
+
throwOnCallError: boolean;
|
|
53
68
|
readonly client: NodeKwil | WebKwil;
|
|
54
69
|
constructor(client: NodeKwil | WebKwil);
|
|
55
70
|
/**
|
|
@@ -82,46 +97,6 @@ declare const createNodeKwilClient: (params: CreateKwilClientParams) => Promise<
|
|
|
82
97
|
*/
|
|
83
98
|
declare const createWebKwilClient: (params: CreateKwilClientParams) => Promise<KwilActionClient>;
|
|
84
99
|
//#endregion
|
|
85
|
-
//#region src/mm-token/create-mm-token-kwil-signer.d.ts
|
|
86
|
-
/** Decoded UKYC capability envelope. KGW signature data is base64url(JSON of this). */
|
|
87
|
-
interface MmTokenEnvelope {
|
|
88
|
-
payload: MmTokenPayload | Record<string, unknown>;
|
|
89
|
-
signature: string;
|
|
90
|
-
}
|
|
91
|
-
interface MmTokenPayload {
|
|
92
|
-
signing_public_key: string;
|
|
93
|
-
storage_id?: string;
|
|
94
|
-
[key: string]: unknown;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* One MM/UKYC capability, valid both as a KGW `mm_token` signer and as the
|
|
98
|
-
* `Authorization: AccessToken …` credential for UKYC blob requests.
|
|
99
|
-
*/
|
|
100
|
-
type MmTokenAuth = KwilSigner & {
|
|
101
|
-
readonly mmTokenPayload: MmTokenPayload | Record<string, unknown>;
|
|
102
|
-
/** Exact encoded envelope KGW and UKYC storage verify. Non-enumerable, so it stays out of logs. */
|
|
103
|
-
readonly accessToken: string;
|
|
104
|
-
/**
|
|
105
|
-
* A capability signs its own envelope, never an arbitrary message. Declared so callers
|
|
106
|
-
* handling a `Wallet` union can keep asking wallets for a message signature.
|
|
107
|
-
*/
|
|
108
|
-
readonly signMessage?: undefined;
|
|
109
|
-
};
|
|
110
|
-
declare function isMmTokenAuth(value: unknown): value is MmTokenAuth;
|
|
111
|
-
/** `storage_id` from the capability token used to construct this signer. */
|
|
112
|
-
declare function mmTokenStorageId(signer: KwilSigner): string;
|
|
113
|
-
/**
|
|
114
|
-
* Build the MM authentication object for one UKYC capability.
|
|
115
|
-
*
|
|
116
|
-
* Pass the MetaMask-issued capability token as a **base64url-encoded** envelope string
|
|
117
|
-
* (what KGW verifies). A decoded `{ payload, signature }` object is also accepted and
|
|
118
|
-
* will be re-encoded.
|
|
119
|
-
*
|
|
120
|
-
* `signMessage` always returns the UTF-8 bytes of that encoded string — KGW ignores the
|
|
121
|
-
* request message and only verifies the envelope.
|
|
122
|
-
*/
|
|
123
|
-
declare function createMmTokenAuth(encodedEnvelope: string | MmTokenEnvelope): MmTokenAuth;
|
|
124
|
-
//#endregion
|
|
125
100
|
//#region src/create-kgw-authenticated-fetch.d.ts
|
|
126
101
|
/** Return true when the response means KGW auth is missing/expired.
|
|
127
102
|
* May read the body only for `application/json` responses (those are probed via a clone). */
|
|
@@ -136,16 +111,16 @@ type CreateKgwAuthenticatedBlobGatewayParams = CreateKgwAuthenticatedFetchParams
|
|
|
136
111
|
url: string;
|
|
137
112
|
maxFetchBytes?: BlobGatewayParams["maxFetchBytes"];
|
|
138
113
|
/**
|
|
139
|
-
* UKYC storage
|
|
140
|
-
*
|
|
114
|
+
* UKYC storage token, sent as `Authorization: AccessToken <token>` next to the KGW session
|
|
115
|
+
* cookie. Only MM operators use it; `BlobGateway.withAccessToken()` swaps it per request.
|
|
141
116
|
*/
|
|
142
|
-
|
|
117
|
+
accessToken?: string;
|
|
143
118
|
};
|
|
144
|
-
declare function createKgwAuthenticatedBlobGateway({ url, maxFetchBytes,
|
|
119
|
+
declare function createKgwAuthenticatedBlobGateway({ url, maxFetchBytes, accessToken, ...fetchParams }: CreateKgwAuthenticatedBlobGatewayParams): BlobGateway;
|
|
145
120
|
declare function createKgwAuthenticatedFetch({ kwilClient, signer, fetchFn, isAuthFailure }: CreateKgwAuthenticatedFetchParams): typeof fetch;
|
|
146
121
|
//#endregion
|
|
147
122
|
//#region src/create-kwil-signer.d.ts
|
|
148
|
-
type Wallet$2 = Wallet$1 | JsonRpcSigner | Wallet | CustomKwilSigner |
|
|
123
|
+
type Wallet$2 = Wallet$1 | JsonRpcSigner | Wallet | CustomKwilSigner | FaceSignSignerProvider;
|
|
149
124
|
interface CustomKwilSigner extends KwilSigner {
|
|
150
125
|
publicAddress: string;
|
|
151
126
|
signatureType: string;
|
|
@@ -153,7 +128,7 @@ interface CustomKwilSigner extends KwilSigner {
|
|
|
153
128
|
walletType: string;
|
|
154
129
|
signMessage: (message: Uint8Array | string) => Promise<Uint8Array>;
|
|
155
130
|
}
|
|
156
|
-
type KwilSignerType = KeyPair | Wallet$1 | nacl.SignKeyPair | JsonRpcSigner | Keypair | KeyPair$1
|
|
131
|
+
type KwilSignerType = KeyPair | Wallet$1 | nacl.SignKeyPair | JsonRpcSigner | Keypair | KeyPair$1;
|
|
157
132
|
type SignerAddress = string;
|
|
158
133
|
type SignerPublicKey = string | undefined;
|
|
159
134
|
/**
|
|
@@ -225,13 +200,16 @@ declare const UpsertWalletAsInserterInputSchema: z.ZodObject<{
|
|
|
225
200
|
user_id: z.ZodUUID;
|
|
226
201
|
address: z.ZodString;
|
|
227
202
|
public_key: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
228
|
-
wallet_type: z.ZodType<
|
|
229
|
-
not_before: z.
|
|
230
|
-
not_after: z.
|
|
203
|
+
wallet_type: z.ZodType<AddWalletType>;
|
|
204
|
+
not_before: z.ZodISODateTime;
|
|
205
|
+
not_after: z.ZodISODateTime;
|
|
231
206
|
signature: z.ZodString;
|
|
232
207
|
}>;
|
|
233
208
|
type UpsertWalletAsInserterInput = z.infer<typeof UpsertWalletAsInserterInputSchema>;
|
|
234
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* WALLET ACTIONS
|
|
211
|
+
* Existing MM wallets count too: a key can't be both an MM wallet and another wallet.
|
|
212
|
+
*/
|
|
235
213
|
declare function upsertWalletAsInserter(kwilClient: KwilActionClient, params: UpsertWalletAsInserterInput): Promise<void>;
|
|
236
214
|
declare const AddWalletMessageInputSchema: z.ZodObject<{
|
|
237
215
|
address: z.ZodString;
|
|
@@ -273,6 +251,10 @@ declare const RemoveWalletInputSchema: z.ZodObject<{
|
|
|
273
251
|
id: z.ZodUUID;
|
|
274
252
|
}>;
|
|
275
253
|
type RemoveWalletInput = z.infer<typeof RemoveWalletInputSchema>;
|
|
254
|
+
/**
|
|
255
|
+
* A user may have an MM wallet next to others (created before MM operators). Without it
|
|
256
|
+
* the user is no longer an MM user, and its ukyc:// credentials could never be wiped.
|
|
257
|
+
*/
|
|
276
258
|
declare function removeWallet(kwilClient: KwilActionClient, params: RemoveWalletInput): Promise<void>;
|
|
277
259
|
declare const CredentialBroaderMessageInputSchema: z.ZodObject<{
|
|
278
260
|
public_notes_signature: z.ZodString;
|
|
@@ -299,6 +281,10 @@ declare const CreatePreliminaryCredentialInputSchema: z.ZodObject<{
|
|
|
299
281
|
broader_signature: z.ZodString;
|
|
300
282
|
}>;
|
|
301
283
|
type CreatePreliminaryCredentialInput = z.infer<typeof CreatePreliminaryCredentialInputSchema>;
|
|
284
|
+
/**
|
|
285
|
+
* Refused for MM users, also when signed in with another wallet: their MM operator stages
|
|
286
|
+
* their credentials (create_preliminary_credential_as_mm_operator), with their storage token.
|
|
287
|
+
*/
|
|
302
288
|
declare function createPreliminaryCredential(kwilClient: KwilActionClient, params: CreatePreliminaryCredentialInput): Promise<void>;
|
|
303
289
|
declare const GetCredentialsOutputSchema: z.ZodObject<{
|
|
304
290
|
id: z.ZodUUID;
|
|
@@ -377,6 +363,7 @@ declare const SharePreliminaryCredentialInputSchema: z.ZodObject<{
|
|
|
377
363
|
locked_until: z.ZodNumber;
|
|
378
364
|
}>;
|
|
379
365
|
type SharePreliminaryCredentialInput = z.infer<typeof SharePreliminaryCredentialInputSchema>;
|
|
366
|
+
/** Refused for MM users, also when signed in with another wallet: their credentials can't be shared. */
|
|
380
367
|
declare function sharePreliminaryCredential(kwilClient: KwilActionClient, params: SharePreliminaryCredentialInput): Promise<void>;
|
|
381
368
|
declare const CreatePreliminaryCredentialsByDwgInputSchema: z.ZodObject<{
|
|
382
369
|
request_id: z.ZodUUID;
|
|
@@ -409,6 +396,7 @@ type CreatePreliminaryCredentialsByDwgInput = z.infer<typeof CreatePreliminaryCr
|
|
|
409
396
|
* Delegated write credential actions
|
|
410
397
|
* For access grant
|
|
411
398
|
* We will use the same ids for preliminary credentials as for credentials, so we need to check if they already exist
|
|
399
|
+
* MM users are managed by their MM operator only.
|
|
412
400
|
* We capture gas upfront to prevent the real credential from being created if the gas is not enough
|
|
413
401
|
* The gas can be refunded fully or partially
|
|
414
402
|
* Temporary: an issuer is not an inserter/caller. A user grants a DWG to an issuer_key;
|
|
@@ -482,6 +470,85 @@ declare const GetSiblingCredentialIdOutputSchema: z.ZodObject<{
|
|
|
482
470
|
}>;
|
|
483
471
|
type GetSiblingCredentialIdOutput = z.infer<typeof GetSiblingCredentialIdOutputSchema>;
|
|
484
472
|
declare function getSiblingCredentialId(kwilClient: KwilActionClient, params: GetSiblingCredentialIdInput): Promise<GetSiblingCredentialIdOutput | undefined>;
|
|
473
|
+
declare const GetUserAsMmOperatorInputSchema: z.ZodObject<{
|
|
474
|
+
storage_token: z.ZodString;
|
|
475
|
+
}>;
|
|
476
|
+
type GetUserAsMmOperatorInput = z.infer<typeof GetUserAsMmOperatorInputSchema>;
|
|
477
|
+
declare const GetUserAsMmOperatorOutputSchema: z.ZodObject<{
|
|
478
|
+
id: z.ZodUUID;
|
|
479
|
+
recipient_encryption_public_key: z.ZodString;
|
|
480
|
+
frozen: z.ZodBoolean;
|
|
481
|
+
}>;
|
|
482
|
+
type GetUserAsMmOperatorOutput = z.infer<typeof GetUserAsMmOperatorOutputSchema>;
|
|
483
|
+
/**
|
|
484
|
+
* MM OPERATOR ACTIONS
|
|
485
|
+
* An MM operator (see mm_operators) creates MM users, stages their ukyc:// credentials and
|
|
486
|
+
* freezes them for a data wipe. It only acts on the MM users it created, and every action
|
|
487
|
+
* also needs a valid UKYC storage token ($storage_token, the bare base64url envelope) minted
|
|
488
|
+
* by the user's app: the operator key alone can't do anything to an MM user. Tokens are
|
|
489
|
+
* verified at @block_timestamp (the last block's time in view calls).
|
|
490
|
+
*/
|
|
491
|
+
declare function getUserAsMmOperator(kwilClient: KwilActionClient, params: GetUserAsMmOperatorInput): Promise<GetUserAsMmOperatorOutput[]>;
|
|
492
|
+
declare const CreateUserAsMmOperatorInputSchema: z.ZodObject<{
|
|
493
|
+
id: z.ZodUUID;
|
|
494
|
+
recipient_encryption_public_key: z.ZodString;
|
|
495
|
+
wallet_id: z.ZodUUID;
|
|
496
|
+
storage_token: z.ZodString;
|
|
497
|
+
}>;
|
|
498
|
+
type CreateUserAsMmOperatorInput = z.infer<typeof CreateUserAsMmOperatorInputSchema>;
|
|
499
|
+
/** The MM wallet key is the storage token's signing key (write token). */
|
|
500
|
+
declare function createUserAsMmOperator(kwilClient: KwilActionClient, params: CreateUserAsMmOperatorInput): Promise<void>;
|
|
501
|
+
declare const GetCredentialsAsMmOperatorInputSchema: z.ZodObject<{
|
|
502
|
+
user_id: z.ZodUUID;
|
|
503
|
+
storage_token: z.ZodString;
|
|
504
|
+
}>;
|
|
505
|
+
type GetCredentialsAsMmOperatorInput = z.infer<typeof GetCredentialsAsMmOperatorInputSchema>;
|
|
506
|
+
declare const GetCredentialsAsMmOperatorOutputSchema: z.ZodObject<{
|
|
507
|
+
id: z.ZodUUID;
|
|
508
|
+
user_id: z.ZodUUID;
|
|
509
|
+
public_notes: z.ZodString;
|
|
510
|
+
content_uri: z.ZodString;
|
|
511
|
+
content_size: z.ZodNumber;
|
|
512
|
+
encryptor_public_key: z.ZodString;
|
|
513
|
+
issuer_auth_public_key: z.ZodString;
|
|
514
|
+
inserter_type: z.ZodString;
|
|
515
|
+
inserter_id: z.ZodString;
|
|
516
|
+
}>;
|
|
517
|
+
type GetCredentialsAsMmOperatorOutput = z.infer<typeof GetCredentialsAsMmOperatorOutputSchema>;
|
|
518
|
+
/** Needs a read token of the user for the user's storage. */
|
|
519
|
+
declare function getCredentialsAsMmOperator(kwilClient: KwilActionClient, params: GetCredentialsAsMmOperatorInput): Promise<GetCredentialsAsMmOperatorOutput[]>;
|
|
520
|
+
declare const CreatePreliminaryCredentialAsMmOperatorInputSchema: z.ZodObject<{
|
|
521
|
+
request_id: z.ZodUUID;
|
|
522
|
+
user_id: z.ZodUUID;
|
|
523
|
+
credential_id: z.ZodUUID;
|
|
524
|
+
issuer_auth_public_key: z.ZodString;
|
|
525
|
+
encryptor_public_key: z.ZodString;
|
|
526
|
+
content_uri: z.ZodString;
|
|
527
|
+
content_size: z.ZodNumber;
|
|
528
|
+
content_hash: z.ZodString;
|
|
529
|
+
public_notes: z.ZodString;
|
|
530
|
+
public_notes_signature: z.ZodString;
|
|
531
|
+
broader_signature: z.ZodString;
|
|
532
|
+
storage_token: z.ZodString;
|
|
533
|
+
}>;
|
|
534
|
+
type CreatePreliminaryCredentialAsMmOperatorInput = z.infer<typeof CreatePreliminaryCredentialAsMmOperatorInputSchema>;
|
|
535
|
+
/**
|
|
536
|
+
* Like create_preliminary_credential, for an MM user. The issuer signs with the user's MM
|
|
537
|
+
* wallet public key as the recipient wallet. Needs a write token of the user; the content URI's
|
|
538
|
+
* storage must be the token's storage and the user's storage (the first credential defines it).
|
|
539
|
+
*/
|
|
540
|
+
declare function createPreliminaryCredentialAsMmOperator(kwilClient: KwilActionClient, params: CreatePreliminaryCredentialAsMmOperatorInput): Promise<void>;
|
|
541
|
+
declare const RequestUserWipeAsMmOperatorInputSchema: z.ZodObject<{
|
|
542
|
+
user_id: z.ZodUUID;
|
|
543
|
+
storage_token: z.ZodString;
|
|
544
|
+
}>;
|
|
545
|
+
type RequestUserWipeAsMmOperatorInput = z.infer<typeof RequestUserWipeAsMmOperatorInputSchema>;
|
|
546
|
+
/**
|
|
547
|
+
* Freezes the MM user: no new credentials, no reads, no finalize. The gateway deletes the
|
|
548
|
+
* user once the UKYC storage is deleted (finalize_mm_user_wipe_as_gateway). No cancel.
|
|
549
|
+
* Needs a delete token of the user for the user's storage, also when already requested.
|
|
550
|
+
*/
|
|
551
|
+
declare function requestUserWipeAsMmOperator(kwilClient: KwilActionClient, params: RequestUserWipeAsMmOperatorInput): Promise<void>;
|
|
485
552
|
declare const AddAttributeAsInserterInputSchema: z.ZodObject<{
|
|
486
553
|
id: z.ZodUUID;
|
|
487
554
|
user_id: z.ZodUUID;
|
|
@@ -739,5 +806,5 @@ declare function removeWallets(kwilClient: KwilActionClient, ids: string[]): Pro
|
|
|
739
806
|
declare const GET_GRANTS_DEFAULT_RECORDS_PER_PAGE = 10;
|
|
740
807
|
declare function getGrants(kwilClient: KwilActionClient, params?: Partial<GetAccessGrantsGrantedInput>): Promise<idOSGrant[]>;
|
|
741
808
|
//#endregion
|
|
742
|
-
export {
|
|
743
|
-
//# sourceMappingURL=index-
|
|
809
|
+
export { CredentialExistAsInserterInput as $, UpdateUserPubKeyAsInserterInputSchema as $n, revokeAccessGrant as $r, GetIssuerFeeOutputSchema as $t, AddWalletMessageOutput as A, RemoveCredentialInput as An, getAllowance as Ar, GetAttributesOutput as At, CheckCallerPayerOutputSchema as B, RescindSharedCredentialInput as Bn, getUserAsInserter as Br, GetCredentialsAsMmOperatorInput as Bt, AddAttributeInputSchema as C, KwilActionClient as Ci, HasLockedAccessGrantsOutputSchema as Cn, editAttribute as Cr, GetAccessGrantsGrantedInputSchema as Ct, AddWalletInputSchema as D, KwilTxFailedError as Di, HasProfileOutputSchema as Dn, getAccessGrantsGranted as Dr, GetAccessGrantsOwnedOutputSchema as Dt, AddWalletInput as E, createWebKwilClient as Ei, HasProfileOutput as En, getAccessGrantsForCredential as Er, GetAccessGrantsOwnedOutput as Et, CheckBalanceOutput as F, RequestBalanceWithdrawalInputSchema as Fn, getCredentialsAsMmOperator as Fr, GetCredentialOwnedOutputSchema as Ft, CreatePreliminaryCredentialsByDwgInput as G, SetCallerPayerInputSchema as Gn, hasProfile as Gr, GetCredentialsOutputSchema as Gt, CreatePreliminaryCredentialAsMmOperatorInputSchema as H, RevokeAccessGrantInput as Hn, getWalletWithBalance as Hr, GetCredentialsAsMmOperatorOutput as Ht, CheckBalanceOutputSchema as I, RequestUserWipeAsMmOperatorInput as In, getCredentialsSharedByUser as Ir, GetCredentialSharedInput as It, CreateUserAsMmOperatorInputSchema as J, SharePreliminaryCredentialInput as Jn, removeWallet as Jr, GetCredentialsSharedByUserOutput as Jt, CreatePreliminaryCredentialsByDwgInputSchema as K, ShareAttributeInput as Kn, removeAttribute as Kr, GetCredentialsSharedByUserInput as Kt, CheckCallerPayerInput as L, RequestUserWipeAsMmOperatorInputSchema as Ln, getIssuerFee as Lr, GetCredentialSharedInputSchema as Lt, AddWalletType as M, RemoveWalletInput as Mn, getCredentialOwned as Mr, GetCredentialOwnedInput as Mt, CheckBalanceInput as N, RemoveWalletInputSchema as Nn, getCredentialShared as Nr, GetCredentialOwnedInputSchema as Nt, AddWalletMessageInput as O, KwilTxPollTimeoutError as Oi, RemoveAttributeInput as On, getAccessGrantsGrantedCount as Or, GetAllowanceOutput as Ot, CheckBalanceInputSchema as P, RequestBalanceWithdrawalInput as Pn, getCredentials as Pr, GetCredentialOwnedOutput as Pt, CredentialBroaderMessageOutputSchema as Q, UpdateUserPubKeyAsInserterInput as Qn, rescindSharedCredential as Qr, GetIssuerFeeOutput as Qt, CheckCallerPayerInputSchema as R, RequestWithdrawalInput as Rn, getSiblingCredentialId as Rr, GetCredentialSharedOutput as Rt, AddAttributeInput as S, createKgwAuthenticatedFetch as Si, HasLockedAccessGrantsOutput as Sn, dwgMessage as Sr, GetAccessGrantsGrantedInput as St, AddUserAsInserterInputSchema as T, createNodeKwilClient as Ti, HasProfileInputSchema as Tn, encryptionPasswordStoreSchema as Tr, GetAccessGrantsGrantedOutputSchema as Tt, CreatePreliminaryCredentialInput as U, RevokeAccessGrantInputSchema as Un, getWallets as Ur, GetCredentialsAsMmOperatorOutputSchema as Ut, CreatePreliminaryCredentialAsMmOperatorInput as V, RescindSharedCredentialInputSchema as Vn, getUserAsMmOperator as Vr, GetCredentialsAsMmOperatorInputSchema as Vt, CreatePreliminaryCredentialInputSchema as W, SetCallerPayerInput as Wn, hasLockedAccessGrants as Wr, GetCredentialsOutput as Wt, CredentialBroaderMessageInputSchema as X, UnsetCallerPayerInput as Xn, requestUserWipeAsMmOperator as Xr, GetIssuerFeeInput as Xt, CredentialBroaderMessageInput as Y, SharePreliminaryCredentialInputSchema as Yn, requestBalanceWithdrawal as Yr, GetCredentialsSharedByUserOutputSchema as Yt, CredentialBroaderMessageOutput as Z, UnsetCallerPayerInputSchema as Zn, requestWithdrawal as Zr, GetIssuerFeeInputSchema as Zt, ActionCostingIdosTokenInput as _, createServerKwilSigner as _i, GetWalletWithBalanceOutputSchema as _n, createPreliminaryCredentialAsMmOperator as _r, GetAccessGrantsForCredentialOutputSchema as _t, idOSCredential as a, upsertWalletAsInserter as ai, GetUserAsInserterInputSchema as an, actionCostingGas as ar, DwgMessageInputSchema as at, AddAttributeAsInserterInput as b, KgwAuthFailurePredicate as bi, HasLockedAccessGrantsInput as bn, credentialBroaderMessage as br, GetAccessGrantsGrantedCountOutput as bt, idOSGrant as c, implicitAddressFromPublicKey as ci, GetUserAsMmOperatorInput as cn, addAttribute as cr, ENCRYPTION_PASSWORD_STORES as ct, idOSWallet as d, KwilSigner$1 as di, GetUserAsMmOperatorOutputSchema as dn, addWallet as dr, EditPublicNotesAsIssuerInput as dt, setCallerPayer as ei, GetSiblingCredentialIdInput as en, UpsertWalletAsInserterInput as er, CredentialExistAsInserterInputSchema as et, removeWallets as f, KwilSignerType as fi, GetUserOutput as fn, addWalletMessage as fr, EditPublicNotesAsIssuerInputSchema as ft, ActionCostingFeeInputSchema as g, createClientKwilSigner as gi, GetWalletWithBalanceOutput as gn, createPreliminaryCredential as gr, GetAccessGrantsForCredentialOutput as gt, ActionCostingFeeInput as h, Wallet$2 as hi, GetWalletWithBalanceInputSchema as hn, checkCallerPayer as hr, GetAccessGrantsForCredentialInputSchema as ht, getGrants as i, updateUserPubKeyAsInserter as ii, GetUserAsInserterInput as in, actionCostingFee as ir, DwgMessageInput as it, AddWalletMessageOutputSchema as j, RemoveCredentialInputSchema as jn, getAttributes as jr, GetAttributesOutputSchema as jt, AddWalletMessageInputSchema as k, RemoveAttributeInputSchema as kn, getAccessGrantsOwned as kr, GetAllowanceOutputSchema as kt, idOSUser as l, signNearMessage as li, GetUserAsMmOperatorInputSchema as ln, addAttributeAsInserter as lr, EditAttributeInput as lt, ADD_WALLET_TYPES as m, SignerPublicKey as mi, GetWalletWithBalanceInput as mn, checkBalance as mr, GetAccessGrantsForCredentialInput as mt, GET_GRANTS_DEFAULT_RECORDS_PER_PAGE as n, sharePreliminaryCredential as ni, GetSiblingCredentialIdOutput as nn, WALLET_TYPES as nr, CredentialExistAsInserterOutputSchema as nt, idOSCredentialListItem as o, walletTypeSchema as oi, GetUserAsInserterOutput as on, actionCostingIdosToken as or, DwgMessageOutput as ot, toDelegatedWriteGrantBaseParams as p, SignerAddress as pi, GetUserOutputSchema as pn, addWalletTypeSchema as pr, EncryptionPasswordStore as pt, CreateUserAsMmOperatorInput as q, ShareAttributeInputSchema as qn, removeCredential as qr, GetCredentialsSharedByUserInputSchema as qt, addWallets as r, unsetCallerPayer as ri, GetSiblingCredentialIdOutputSchema as rn, WalletType as rr, DataType as rt, idOSDelegatedWriteGrant as s, getNearFullAccessPublicKeys as si, GetUserAsInserterOutputSchema as sn, actionSchema as sr, DwgMessageOutputSchema as st, DelegatedWriteGrantBaseParams as t, shareAttribute as ti, GetSiblingCredentialIdInputSchema as tn, UpsertWalletAsInserterInputSchema as tr, CredentialExistAsInserterOutput as tt, idOSUserAttribute as u, CustomKwilSigner as ui, GetUserAsMmOperatorOutput as un, addUserAsInserter as ur, EditAttributeInputSchema as ut, ActionCostingIdosTokenInputSchema as v, CreateKgwAuthenticatedBlobGatewayParams as vi, GetWalletsOutput as vn, createPreliminaryCredentialsByDwg as vr, GetAccessGrantsGrantedCountInput as vt, AddUserAsInserterInput as w, KwilCallError as wi, HasProfileInput as wn, editPublicNotesAsIssuer as wr, GetAccessGrantsGrantedOutput as wt, AddAttributeAsInserterInputSchema as x, createKgwAuthenticatedBlobGateway as xi, HasLockedAccessGrantsInputSchema as xn, credentialExistAsInserter as xr, GetAccessGrantsGrantedCountOutputSchema as xt, ActionSchemaElement as y, CreateKgwAuthenticatedFetchParams as yi, GetWalletsOutputSchema as yn, createUserAsMmOperator as yr, GetAccessGrantsGrantedCountInputSchema as yt, CheckCallerPayerOutput as z, RequestWithdrawalInputSchema as zn, getUser as zr, GetCredentialSharedOutputSchema as zt };
|
|
810
|
+
//# sourceMappingURL=index-Dc_rffi1.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-Dc_rffi1.d.mts","names":[],"sources":["../src/wait-for-kwil-tx.ts","../src/create-kwil-client.ts","../src/create-kgw-authenticated-fetch.ts","../src/create-kwil-signer.ts","../src/near/create-near-wallet-kwil-signer.ts","../src/actions/actions.ts","../src/actions/index.ts"],"mappings":";;;;;;;;;;;;cAca,0BAA0B;WAInC;WACA;WACA;WACA;WANO;EAET,YACE,gBACA,cACA,aACA;;cAMS,+BAA+B;WAIxC;WACA;WAJO;EAET,YACE,gBACA,oBACA;IAAY;;;;;KCnBX;EACH;EACA;;KAGG,qBAAqB;KACrB,mBAAmB;KAEnB,uBACF,QAAQ;EACP,MAAM;EAEN,QAAQ,OAAO,YAAY;;KAI1B,8BAA8B,kBA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,kBACZ,QAAQ,wBACP;cASU,qCAAqC,EAAE;EAClD,OAAO,EAAE;EACT,gBAAgB,EAAE;;KAMR,gCAAgC,EAAE,aAAa;iBAErC,yBACpB,YAAY,kBACZ,QAAQ,gCACP;;;KCj3ES,WAAW;KACX,YAAY;KACZ,iBAAiB;KACjB,yBAAyB;KACzB,oBAAoB;KACpB,aAAa;KACb,0BAA0B;KAE1B;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGc,gCACd,QAAQ,0BACP;iBA0BmB,WACpB,YAAY,kBACZ,SAAS,mBACR;iBAImB,cAAc,YAAY,kBAAkB,gBAAgB;cAIrE;iBAES,UACpB,YAAY,kBACZ,SAAQ,QAAQ,+BAKf,QAAQ"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { CreateKgwAuthenticatedBlobGatewayParams, CreateKgwAuthenticatedFetchParams, CustomKwilSigner, KgwAuthFailurePredicate, KwilActionClient, KwilSigner, KwilSignerType, KwilTxFailedError, KwilTxPollTimeoutError,
|
|
1
|
+
import { Ci as KwilActionClient, Di as KwilTxFailedError, Ei as createWebKwilClient, Oi as KwilTxPollTimeoutError, Si as createKgwAuthenticatedFetch, Ti as createNodeKwilClient, _i as createServerKwilSigner, bi as KgwAuthFailurePredicate, ci as implicitAddressFromPublicKey, di as KwilSigner, fi as KwilSignerType, gi as createClientKwilSigner, hi as Wallet, li as signNearMessage, mi as SignerPublicKey, pi as SignerAddress, si as getNearFullAccessPublicKeys, ui as CustomKwilSigner, vi as CreateKgwAuthenticatedBlobGatewayParams, wi as KwilCallError, xi as createKgwAuthenticatedBlobGateway, yi as CreateKgwAuthenticatedFetchParams } from "./index-Dc_rffi1.mjs";
|
|
2
|
+
export { CreateKgwAuthenticatedBlobGatewayParams, CreateKgwAuthenticatedFetchParams, CustomKwilSigner, KgwAuthFailurePredicate, KwilActionClient, KwilCallError, KwilSigner, KwilSignerType, KwilTxFailedError, KwilTxPollTimeoutError, SignerAddress, SignerPublicKey, Wallet, createClientKwilSigner, createKgwAuthenticatedBlobGateway, createKgwAuthenticatedFetch, createNodeKwilClient, createServerKwilSigner, createWebKwilClient, getNearFullAccessPublicKeys, implicitAddressFromPublicKey, signNearMessage };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{actionSchema as e}from"./actions/index.mjs";import{t}from"./facesign-signer-CTPPUFxT.mjs";import{i as n,n as r,r as i}from"./nep413-D_D-6Yf6.mjs";import{getXrpPublicKey as a,getXrpTxHash as o,looksLikeXrpWallet as s}from"./xrp/utils.mjs";import{KwilSigner as c,KwilSigner as l,NodeKwil as u,WebKwil as d}from"@idos-network/kwil-js";import f from"tiny-invariant";import{BlobGateway as p}from"@idos-network/utils/blob-gateway";import{base64Decode as m,base64UrlDecode as ee,base64UrlEncode as h,binaryWriteUint16BE as g,bs58Decode as _,bs58Encode as v,bytesConcat as y,hexDecode as te,hexEncode as b,utf8Decode as x,utf8Encode as S}from"@idos-network/utils/codecs";import C from"tweetnacl";var w=class extends Error{txHash;code;log;height;name=`KwilTxFailedError`;constructor(e,t,n,r){super(`Kwil transaction ${e} failed at height ${r} (code ${t}): ${n}`),this.txHash=e,this.code=t,this.log=n,this.height=r}},T=class extends Error{txHash;deadlineMs;name=`KwilTxPollTimeoutError`;constructor(e,t,n){let r=n?.cause instanceof Error?n.cause.message:n?.cause==null?void 0:String(n.cause);super(r?`Timed out after ${t}ms waiting for Kwil transaction ${e}: last error: ${r}`:`Timed out after ${t}ms waiting for Kwil transaction ${e}`,n?.cause===void 0?void 0:{cause:n.cause}),this.txHash=e,this.deadlineMs=t}};function E(e){return new Promise(t=>setTimeout(t,e))}function ne(e){return Math.min(e*1.5,2e3)}function re(e){return e+Math.floor(Math.random()*101)}function ie(e){return e.height>0}async function ae(e,t,n=9e4){let r=Date.now()+n,i=300,a;for(;Date.now()<r;){let n;try{n=(await e(t)).data}catch(e){a=e}if(n&&ie(n)){if(n.tx_result.code!==0)throw new w(t,n.tx_result.code,n.tx_result.log,n.height);return}let o=re(i),s=r-Date.now();if(s<=0)break;await E(Math.min(o,s)),i=ne(i)}throw new T(t,n,a===void 0?void 0:{cause:a})}var D=class{signer;client;constructor(e){this.client=e}#e(t,n={}){return!n||!Object.keys(n).length?[]:e[t].map(({name:e})=>{let t=n[e];return t===``||t===0?t:t??null})}#t(t){return e[t].map(e=>e.type)}async call(e,t=this.signer){let n={name:e.name,namespace:`main`,inputs:this.#e(e.name,e.inputs),types:this.#t(e.name)};return(await this.client.call(n,t))?.data?.result}async execute(e,t=this.signer,n=!0){f(t,`Signer is not set, you must set it before executing an action`);let r={name:e.name,namespace:`main`,description:e.description,inputs:[this.#e(e.name,e.inputs)],types:this.#t(e.name)},i=(await this.client.execute(r,t,!1)).data?.tx_hash;if(!i)throw Error(`Kwil execute "${e.name}" did not return a transaction hash`);return n&&await this.waitForTx(i),i}async waitForTx(e){await ae(e=>this.client.txInfo(e),e)}setSigner(e){this.signer=e}};const O=e=>async({nodeUrl:t,chainId:n})=>{let r=new e({kwilProvider:t,chainId:``});return n||=(await r.chainInfo({disableWarning:!0})).data?.chain_id,f(n,"Can't discover `chainId`. You must pass it explicitly."),new D(new e({kwilProvider:t,chainId:n,timeout:3e4}))},oe=O(u),k=O(d);function A(e){return typeof e==`object`&&!!e&&`signatureType`in e&&e.signatureType===`mm_token`&&`identifier`in e&&`signer`in e&&typeof e.accessToken==`string`}function j(e){let t=e.mmTokenPayload?.storage_id;if(typeof t!=`string`||!t.trim())throw Error(`mm_token payload is missing storage_id`);return t.trim()}function M(e){return typeof e==`object`&&!!e&&`payload`in e&&e.payload!==null&&typeof e.payload==`object`&&!Array.isArray(e.payload)&&`signature`in e&&typeof e.signature==`string`}function N(e,t){try{return JSON.parse(x(e))}catch(e){throw Error(t,{cause:e})}}function P(e,t){try{return ee(e)}catch(e){throw Error(t,{cause:e})}}function F(e){let t,n;if(typeof e==`string`){let r=e.trim();if(!r)throw Error(`Invalid mm_token envelope: empty`);t=r;let i=N(P(r,`Invalid mm_token envelope encoding`),`Invalid mm_token envelope JSON`);if(!M(i))throw Error(`Invalid mm_token envelope: expected payload object and signature string`);n=i}else{if(!M(e))throw Error(`Invalid mm_token envelope: expected payload object and signature string`);n=e,t=h(S(JSON.stringify(n)))}let r=S(t),i=P(n.signature,`Invalid mm_token envelope signature encoding`);if(i.length!==64)throw Error(`Invalid mm_token signature length: expected 64, got ${i.length}`);let a=n.payload.signing_public_key;if(typeof a!=`string`)throw Error(`Invalid mm_token payload: missing signing_public_key`);let o=P(a,`Invalid mm_token signing_public_key encoding`);if(o.length!==32)throw Error(`Invalid mm_token signing_public_key length: expected 32, got ${o.length}`);let s=Object.assign(new l(async()=>r.slice(),o,`mm_token`),{mmTokenPayload:n.payload});return Object.defineProperty(s,"accessToken",{value:t,enumerable:!1})}function I({url:e,maxFetchBytes:t,mmAuth:n,...r}){let i=n??(A(r.signer)?r.signer:void 0);return new p({url:e,maxFetchBytes:t,accessToken:i?.accessToken,fetchFn:L(r)})}function L({kwilClient:e,signer:t,fetchFn:n=fetch,isAuthFailure:r=se}){let i=K(e),a,o=async()=>(a??=i.authenticateKGWAndSetCookie(t).finally(()=>{a=void 0}),a),s=async()=>{let e=i.getKgwCookie();return e?{cookie:e,refreshed:!1}:{cookie:await o(),refreshed:!0}};return async(e,t)=>{let{cookie:i}=await s(),a=await V(e,t),c=await n(...J(e,H(a),i)),l=R(c);if(!await r(l.response))return c;await z(l.discardResponses);let u=await o();return n(...J(e,H(a),u))}}function R(e){if(e.headers.get(`content-type`)?.includes(`application/json`)){let t=e.clone();return{response:t,discardResponses:[e,t]}}return{response:e,discardResponses:[e]}}async function z(e){await Promise.all(e.map(B))}async function B(e){if(!e.bodyUsed&&e.body)try{await e.body.cancel()}catch{}}async function V(e,t){if(t?.body!=null)return{requestInit:t,bufferedBody:await U(t.body)};if(e instanceof Request&&e.body!=null){let n=e.clone();return{requestInit:{...t,method:t?.method??e.method},bufferedBody:await U(n.body)}}return{requestInit:t}}function H({requestInit:e,bufferedBody:t}){return t?{...e,body:G(t)}:e}async function U(e){if(typeof e==`string`||e instanceof Blob||e instanceof ArrayBuffer||e instanceof URLSearchParams)return{kind:`body`,value:e};if(ArrayBuffer.isView(e))return{kind:`body`,value:new Uint8Array(e.buffer,e.byteOffset,e.byteLength)};if(e instanceof FormData){let t=[];return e.forEach((e,n)=>{t.push(W(n,e))}),{kind:`form-data`,entries:await Promise.all(t)}}return e instanceof ReadableStream?{kind:`body`,value:await new Response(e).arrayBuffer()}:{kind:`body`,value:e}}async function W(e,t){return typeof t==`string`?{key:e,value:t}:{key:e,value:await new Response(t).arrayBuffer(),fileName:t instanceof File?t.name:`blob`,type:t.type||`application/octet-stream`}}function G(e){if(e.kind===`body`)return e.value;let t=new FormData;for(let n of e.entries)`fileName`in n?t.append(n.key,new Blob([n.value],{type:n.type}),n.fileName):t.append(n.key,n.value);return t}function K(e){if(!(e.client instanceof u))throw Error(`KGW authenticated fetch can only be created from a NodeKwil client`);if(!q(e.client))throw Error(`NodeKwil client does not expose KGW session cookie helpers`);return e.client}function q(e){let t=e;return typeof t.getKgwCookie==`function`&&typeof t.authenticateKGWAndSetCookie==`function`}function J(e,t,n){let r=new Headers(e instanceof Request?e.headers:void 0);return t?.headers&&new Headers(t.headers).forEach((e,t)=>{r.set(t,e)}),r.set(`Cookie`,n),[e,{...t,headers:r}]}async function se(e){if(e.status===401)return!0;if(!e.headers.get(`content-type`)?.includes(`application/json`))return!1;try{return(await e.json()).error?.code===-901}catch{return!1}}const ce={mainnet:{networkId:`mainnet`,nodeUrl:`https://rpc.mainnet.near.org`},testnet:{networkId:`testnet`,nodeUrl:`https://rpc.testnet.near.org`},betanet:{networkId:`betanet`,nodeUrl:`https://rpc.betanet.near.org`},shardnet:{networkId:`shardnet`,nodeUrl:`https://rpc.shardnet.near.org`}},le=e=>e.endsWith(`.near`)?`mainnet`:e.endsWith(`.testnet`)?`testnet`:e.endsWith(`.betanet`)?`betanet`:e.endsWith(`.shardnet`)?`shardnet`:`testnet`,ue=e=>{let t=le(e),n=ce[t];return{networkId:n.networkId,nodeUrl:n.nodeUrl}},de=[`browser`,`injected`,`instant-link`,`hardware`,`bridge`];function fe(e){return typeof e==`object`&&!!e&&`id`in e&&`metadata`in e&&`type`in e&&typeof e.type==`string`&&de.includes(e.type)}var Y=class{bytes;constructor(e=32){this.bytes=crypto.getRandomValues(new Uint8Array(e))}get clampUTF8(){return this.bytes.map(e=>e&127)}};function X(e,t){return async r=>{let i=typeof r==`string`?r:x(r);if(!e.signMessage)throw Error(`Only wallets with signMessage are supported.`);let a=Buffer.from(new Y(32).bytes),{nonce:o=a,signature:s,callbackUrl:c}=await e.signMessage({message:i,recipient:t,nonce:a}),l=n({message:i,nonce:Array.from(o),recipient:t,callbackUrl:c});return y(g(l.length),l,m(s))}}function Z(e){let t=e.replace(/^ed25519:/,``);return b(_(t),!0)}async function Q(e){let t;try{t=(await import(`near-api-js`)).connect}catch{throw Error(`Can't load near-api-js`)}let n=ue(e),r=await t(n);try{return(await r.connection.provider.query({request_type:`view_access_key_list`,finality:`final`,account_id:e})).keys.filter(e=>e.access_key.permission===`FullAccess`)?.map(e=>e.public_key)}catch{return}}function pe(e){let t=new URLSearchParams(e.startsWith(`#`)?e.slice(1):e),n=t.get(`signature`);return{accountId:t.get(`accountId`)??void 0,publicKey:t.get(`publicKey`)??void 0,signature:n?.replaceAll(` `,`+`),error:t.get(`error`)??void 0}}function me(){let e=pe(window.location.hash);if(!e.accountId&&!e.publicKey&&!e.signature&&!e.error)return e;let t=new URLSearchParams(window.location.hash.slice(1));for(let e of[`accountId`,`publicKey`,`signature`,`error`,`state`])t.delete(e);let n=t.toString();return window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${n?`#${n}`:``}`),e}function he(e,t,n,r,a,o){let s=o.split(`:`);if(s.length!==2||s[0]!==`ed25519`||!s[1]||t.length!==32)return!1;try{let o=_(s[1]),c=m(a);return o.length!==32||c.length!==64?!1:C.sign.detached.verify(i({message:e,nonce:t,recipient:n,callbackUrl:r}),c,o)}catch{return!1}}async function ge(e,t,n,r){if(e.error||!e.signature||!e.publicKey||e.accountId!==t)return;let i=await r.get(`sign-last-message`),a=await r.get(`sign-last-nonce`),o=await r.get(`sign-last-url`);if(i&&a&&o&&he(i,Uint8Array.from(a),n,o,e.signature,e.publicKey)&&(await Q(t))?.includes(e.publicKey))return{signature:e.signature,publicKey:e.publicKey}}async function _e(e,t,n=`idos.network`){let r=await X(e,n)(t);return b(r)}async function ve(e,t,n,r,i=`idos.network`){if(!e.signMessage)throw Error(`Only wallets with signMessage are supported.`);if(e.id===`my-near-wallet`){let r=me(),a=await ge(r,t,i,n);a&&(await n.set(`signer-address`,t),await n.set(`signer-public-key`,a.publicKey));let o=e.signMessage.bind(e);e.signMessage=async({message:e,recipient:i})=>{if(r.error)return Promise.reject();let s=await n.get(`sign-last-message`),c=await n.get(`sign-last-nonce`);if(a&&e===s&&c){let r=Buffer.from(c),i=await n.get(`sign-last-url`);return Promise.resolve({accountId:t,publicKey:a.publicKey,signature:a.signature,nonce:r,message:e,callbackUrl:i})}let l=window.location.href,u=Buffer.from(new Y(32).clampUTF8);return await n.set(`sign-last-message`,e),await n.set(`sign-last-nonce`,Array.from(u)),await n.set(`sign-last-url`,l),o({message:e,nonce:u,recipient:i,callbackUrl:l}),new Promise(()=>({}))}}let a=await n.get(`signer-address`),o=await n.get(`signer-public-key`);if(a!==t||!o){n.reset(),await r.client.auth.logoutKGW();let a=Buffer.from(new Y(32).bytes),s=await e.signMessage({message:`idOS authentication`,recipient:i,nonce:a});if(!s)throw Error(`signMessage returned no result`);({publicKey:o}=s),await n.set(`signer-address`,t),await n.set(`signer-public-key`,o)}let s=X(e,i);return{kwilSigner:new l(s,Z(o),`nep413`),publicKey:o}}async function ye(e,t,n,r,i){let a=await n.get(`signer-address`),s=await n.get(`signer-public-key`);if(a!==t||s&&s!==i)try{console.log(`logoutKGW`,r)}catch(e){console.error(`Failed to logout KGW:`,e)}return await n.set(`signer-address`,t),await n.set(`signer-public-key`,i),new l(async t=>{let n=await o(t,e);if(!n||!/^(?:[0-9a-f]{2})+$/i.test(n))throw Error(`Failed to sign transaction with XRP`);return Buffer.from(n,`hex`)},i,`xrpl`)}function be(e){return typeof e==`object`&&!!e&&`publicKey`in e&&e.publicKey instanceof Uint8Array&&e.publicKey.length===C.sign.publicKeyLength&&`secretKey`in e&&e.secretKey instanceof Uint8Array&&e.secretKey.length===C.sign.secretKeyLength}function $(e){return typeof e==`object`&&!!e&&`getPublicKey`in e&&`sign`in e&&typeof e.getPublicKey==`function`&&typeof e.sign==`function`}function xe(e){return typeof e==`object`&&!!e&&`publicKey`in e&&`sign`in e&&`canSign`in e&&typeof e.publicKey==`function`&&typeof e.sign==`function`&&typeof e.canSign==`function`}function Se(e){return typeof e==`object`&&!!e&&`publicAddress`in e&&`signatureType`in e&&`publicKey`in e&&`signMessage`in e}function Ce(e){return!!e&&typeof e==`object`&&`privateKey`in e&&`publicKey`in e}async function we(e){if(A(e))return[e,h(e.identifier)];if(be(e))return[new l(async t=>C.sign.detached(t,e.secretKey),e.publicKey,`ed25519`),Z(v(e.publicKey))];if($(e)){let t=e.getPublicKey().toString(),n=Z(t);return[new l(r(`idos-issuer`)(e),n,`nep413`),t]}if(xe(e)){let t=e.publicKey(),n=e.rawPublicKey();return[new l(async t=>e.sign(Buffer.from(t)),n,`ed25519`),t]}if(Ce(e)){let t;try{t=await import(`ripple-keypairs`)}catch(e){throw Error(`Can't load ripple-keypairs`,{cause:e})}return[new l(async n=>te(t.sign(b(n),e.privateKey)),e.publicKey,`xrpl`),e.publicKey]}return`address`in e?[new l(e,e.address),e.address]:(e=>{throw Error("Invalid `signer` type")})(e)}async function Te(e,n,r){if(`connect`in r&&`address`in r){r=r;let t=await r.getAddress();if(await e.get(`signer-address`)!==t){e.set(`signer-address`,t);try{await n.client.auth.logoutKGW()}catch(e){console.log(`error logoutKGW`,e)}}return[new l(r,t),t,void 0,`EVM`]}if(fe(r)){let t=await r.getAccounts(),{kwilSigner:i,publicKey:a}=await ve(r,t[0].accountId,e,n);return[i,t[0].accountId,a,`NEAR`]}if(s(r)){let{address:t,publicKey:i}=await a(r);if(!t)throw Error(`Failed to get XRP address`);return[await ye(r,t,e,n,i),t,i,`XRPL`]}if(A(r)){let t=h(r.identifier);if(await e.get(`signer-address`)!==t){e.set(`signer-address`,t);try{await n.client.auth.logoutKGW()}catch(e){console.log(`error logoutKGW`,e)}}return[r,t,t,`MM`]}if(Se(r)||r instanceof t){if(await e.get(`signer-address`)!==r.publicAddress){e.set(`signer-address`,r.publicAddress);try{await n.client.auth.logoutKGW()}catch(e){console.log(`error logoutKGW`,e)}}return[new l(async e=>r.signMessage(e),r.publicAddress,`ed25519`),r.publicAddress,r.publicKey,r.walletType]}return(e=>{throw Error("Invalid `signer` type")})(r)}export{D as KwilActionClient,c as KwilSigner,w as KwilTxFailedError,T as KwilTxPollTimeoutError,Te as createClientKwilSigner,I as createKgwAuthenticatedBlobGateway,L as createKgwAuthenticatedFetch,F as createMmTokenAuth,oe as createNodeKwilClient,we as createServerKwilSigner,k as createWebKwilClient,Q as getNearFullAccessPublicKeys,Z as implicitAddressFromPublicKey,A as isMmTokenAuth,j as mmTokenStorageId,_e as signNearMessage};
|
|
1
|
+
import{actionSchema as e}from"./actions/index.mjs";import{t}from"./facesign-signer-CTPPUFxT.mjs";import{i as n,n as r,r as i}from"./nep413-D_D-6Yf6.mjs";import{getXrpPublicKey as a,getXrpTxHash as o,looksLikeXrpWallet as s}from"./xrp/utils.mjs";import{KwilSigner as c,KwilSigner as l,NodeKwil as u,WebKwil as d}from"@idos-network/kwil-js";import f from"tiny-invariant";import{BlobGateway as p}from"@idos-network/utils/blob-gateway";import{base64Decode as m,binaryWriteUint16BE as h,bs58Decode as g,bs58Encode as _,bytesConcat as v,hexDecode as y,hexEncode as b,utf8Decode as x}from"@idos-network/utils/codecs";import S from"tweetnacl";var C=class extends Error{txHash;code;log;height;name=`KwilTxFailedError`;constructor(e,t,n,r){super(`Kwil transaction ${e} failed at height ${r} (code ${t}): ${n}`),this.txHash=e,this.code=t,this.log=n,this.height=r}},w=class extends Error{txHash;deadlineMs;name=`KwilTxPollTimeoutError`;constructor(e,t,n){let r=n?.cause instanceof Error?n.cause.message:n?.cause==null?void 0:String(n.cause);super(r?`Timed out after ${t}ms waiting for Kwil transaction ${e}: last error: ${r}`:`Timed out after ${t}ms waiting for Kwil transaction ${e}`,n?.cause===void 0?void 0:{cause:n.cause}),this.txHash=e,this.deadlineMs=t}};function ee(e){return new Promise(t=>setTimeout(t,e))}function te(e){return Math.min(e*1.5,2e3)}function ne(e){return e+Math.floor(Math.random()*101)}function re(e){return e.height>0}async function ie(e,t,n=9e4){let r=Date.now()+n,i=300,a;for(;Date.now()<r;){let n;try{n=(await e(t)).data}catch(e){a=e}if(n&&re(n)){if(n.tx_result.code!==0)throw new C(t,n.tx_result.code,n.tx_result.log,n.height);return}let o=ne(i),s=r-Date.now();if(s<=0)break;await ee(Math.min(o,s)),i=te(i)}throw new w(t,n,a===void 0?void 0:{cause:a})}var T=class extends Error{actionName;name=`KwilCallError`;constructor(e,t){super(t),this.actionName=e}},E=class{signer;throwOnCallError=!1;client;constructor(e){this.client=e}#e(t,n={}){return!n||!Object.keys(n).length?[]:e[t].map(({name:e})=>{let t=n[e];return t===``||t===0?t:t??null})}#t(t){return e[t].map(e=>e.type)}async call(e,t=this.signer){let n={name:e.name,namespace:`main`,inputs:this.#e(e.name,e.inputs),types:this.#t(e.name)},r=await this.client.call(n,t),i=r?.data?.error;if(this.throwOnCallError&&i)throw new T(e.name,i);return r?.data?.result}async execute(e,t=this.signer,n=!0){f(t,`Signer is not set, you must set it before executing an action`);let r={name:e.name,namespace:`main`,description:e.description,inputs:[this.#e(e.name,e.inputs)],types:this.#t(e.name)},i=(await this.client.execute(r,t,!1)).data?.tx_hash;if(!i)throw Error(`Kwil execute "${e.name}" did not return a transaction hash`);return n&&await this.waitForTx(i),i}async waitForTx(e){await ie(e=>this.client.txInfo(e),e)}setSigner(e){this.signer=e}};const D=e=>async({nodeUrl:t,chainId:n})=>{let r=new e({kwilProvider:t,chainId:``});return n||=(await r.chainInfo({disableWarning:!0})).data?.chain_id,f(n,"Can't discover `chainId`. You must pass it explicitly."),new E(new e({kwilProvider:t,chainId:n,timeout:3e4}))},O=D(u),k=D(d);function A({url:e,maxFetchBytes:t,accessToken:n,...r}){return new p({url:e,maxFetchBytes:t,accessToken:n,fetchFn:j(r)})}function j({kwilClient:e,signer:t,fetchFn:n=fetch,isAuthFailure:r=W}){let i=B(e),a,o=async()=>(a??=i.authenticateKGWAndSetCookie(t).finally(()=>{a=void 0}),a),s=async()=>{let e=i.getKgwCookie();return e?{cookie:e,refreshed:!1}:{cookie:await o(),refreshed:!0}};return async(e,t)=>{let{cookie:i}=await s(),a=await F(e,t),c=await n(...H(e,I(a),i)),l=M(c);if(!await r(l.response))return c;await N(l.discardResponses);let u=await o();return n(...H(e,I(a),u))}}function M(e){if(e.headers.get(`content-type`)?.includes(`application/json`)){let t=e.clone();return{response:t,discardResponses:[e,t]}}return{response:e,discardResponses:[e]}}async function N(e){await Promise.all(e.map(P))}async function P(e){if(!e.bodyUsed&&e.body)try{await e.body.cancel()}catch{}}async function F(e,t){if(t?.body!=null)return{requestInit:t,bufferedBody:await L(t.body)};if(e instanceof Request&&e.body!=null){let n=e.clone();return{requestInit:{...t,method:t?.method??e.method},bufferedBody:await L(n.body)}}return{requestInit:t}}function I({requestInit:e,bufferedBody:t}){return t?{...e,body:z(t)}:e}async function L(e){if(typeof e==`string`||e instanceof Blob||e instanceof ArrayBuffer||e instanceof URLSearchParams)return{kind:`body`,value:e};if(ArrayBuffer.isView(e))return{kind:`body`,value:new Uint8Array(e.buffer,e.byteOffset,e.byteLength)};if(e instanceof FormData){let t=[];return e.forEach((e,n)=>{t.push(R(n,e))}),{kind:`form-data`,entries:await Promise.all(t)}}return e instanceof ReadableStream?{kind:`body`,value:await new Response(e).arrayBuffer()}:{kind:`body`,value:e}}async function R(e,t){return typeof t==`string`?{key:e,value:t}:{key:e,value:await new Response(t).arrayBuffer(),fileName:t instanceof File?t.name:`blob`,type:t.type||`application/octet-stream`}}function z(e){if(e.kind===`body`)return e.value;let t=new FormData;for(let n of e.entries)`fileName`in n?t.append(n.key,new Blob([n.value],{type:n.type}),n.fileName):t.append(n.key,n.value);return t}function B(e){if(!(e.client instanceof u))throw Error(`KGW authenticated fetch can only be created from a NodeKwil client`);if(!V(e.client))throw Error(`NodeKwil client does not expose KGW session cookie helpers`);return e.client}function V(e){let t=e;return typeof t.getKgwCookie==`function`&&typeof t.authenticateKGWAndSetCookie==`function`}function H(e,t,n){let r=new Headers(e instanceof Request?e.headers:void 0);return t?.headers&&new Headers(t.headers).forEach((e,t)=>{r.set(t,e)}),r.set(`Cookie`,n),[e,{...t,headers:r}]}const U=new Set([`MM_TOKEN_INVALID`,`MM_TOKEN_EXPIRED`]);async function W(e){if(!e.headers.get(`content-type`)?.includes(`application/json`))return e.status===401;try{let t=await e.json();return e.status===401?!(typeof t.code==`string`&&U.has(t.code)):t.error?.code===-901}catch{return e.status===401}}const ae={mainnet:{networkId:`mainnet`,nodeUrl:`https://rpc.mainnet.near.org`},testnet:{networkId:`testnet`,nodeUrl:`https://rpc.testnet.near.org`},betanet:{networkId:`betanet`,nodeUrl:`https://rpc.betanet.near.org`},shardnet:{networkId:`shardnet`,nodeUrl:`https://rpc.shardnet.near.org`}},G=e=>e.endsWith(`.near`)?`mainnet`:e.endsWith(`.testnet`)?`testnet`:e.endsWith(`.betanet`)?`betanet`:e.endsWith(`.shardnet`)?`shardnet`:`testnet`,K=e=>{let t=G(e),n=ae[t];return{networkId:n.networkId,nodeUrl:n.nodeUrl}},q=[`browser`,`injected`,`instant-link`,`hardware`,`bridge`];function J(e){return typeof e==`object`&&!!e&&`id`in e&&`metadata`in e&&`type`in e&&typeof e.type==`string`&&q.includes(e.type)}var Y=class{bytes;constructor(e=32){this.bytes=crypto.getRandomValues(new Uint8Array(e))}get clampUTF8(){return this.bytes.map(e=>e&127)}};function X(e,t){return async r=>{let i=typeof r==`string`?r:x(r);if(!e.signMessage)throw Error(`Only wallets with signMessage are supported.`);let a=Buffer.from(new Y(32).bytes),{nonce:o=a,signature:s,callbackUrl:c}=await e.signMessage({message:i,recipient:t,nonce:a}),l=n({message:i,nonce:Array.from(o),recipient:t,callbackUrl:c});return v(h(l.length),l,m(s))}}function Z(e){let t=e.replace(/^ed25519:/,``);return b(g(t),!0)}async function Q(e){let t;try{t=(await import(`near-api-js`)).connect}catch{throw Error(`Can't load near-api-js`)}let n=K(e),r=await t(n);try{return(await r.connection.provider.query({request_type:`view_access_key_list`,finality:`final`,account_id:e})).keys.filter(e=>e.access_key.permission===`FullAccess`)?.map(e=>e.public_key)}catch{return}}function oe(e){let t=new URLSearchParams(e.startsWith(`#`)?e.slice(1):e),n=t.get(`signature`);return{accountId:t.get(`accountId`)??void 0,publicKey:t.get(`publicKey`)??void 0,signature:n?.replaceAll(` `,`+`),error:t.get(`error`)??void 0}}function se(){let e=oe(window.location.hash);if(!e.accountId&&!e.publicKey&&!e.signature&&!e.error)return e;let t=new URLSearchParams(window.location.hash.slice(1));for(let e of[`accountId`,`publicKey`,`signature`,`error`,`state`])t.delete(e);let n=t.toString();return window.history.replaceState(null,``,`${window.location.pathname}${window.location.search}${n?`#${n}`:``}`),e}function ce(e,t,n,r,a,o){let s=o.split(`:`);if(s.length!==2||s[0]!==`ed25519`||!s[1]||t.length!==32)return!1;try{let o=g(s[1]),c=m(a);return o.length!==32||c.length!==64?!1:S.sign.detached.verify(i({message:e,nonce:t,recipient:n,callbackUrl:r}),c,o)}catch{return!1}}async function le(e,t,n,r){if(e.error||!e.signature||!e.publicKey||e.accountId!==t)return;let i=await r.get(`sign-last-message`),a=await r.get(`sign-last-nonce`),o=await r.get(`sign-last-url`);if(i&&a&&o&&ce(i,Uint8Array.from(a),n,o,e.signature,e.publicKey)&&(await Q(t))?.includes(e.publicKey))return{signature:e.signature,publicKey:e.publicKey}}async function ue(e,t,n=`idos.network`){let r=await X(e,n)(t);return b(r)}async function de(e,t,n,r,i=`idos.network`){if(!e.signMessage)throw Error(`Only wallets with signMessage are supported.`);if(e.id===`my-near-wallet`){let r=se(),a=await le(r,t,i,n);a&&(await n.set(`signer-address`,t),await n.set(`signer-public-key`,a.publicKey));let o=e.signMessage.bind(e);e.signMessage=async({message:e,recipient:i})=>{if(r.error)return Promise.reject();let s=await n.get(`sign-last-message`),c=await n.get(`sign-last-nonce`);if(a&&e===s&&c){let r=Buffer.from(c),i=await n.get(`sign-last-url`);return Promise.resolve({accountId:t,publicKey:a.publicKey,signature:a.signature,nonce:r,message:e,callbackUrl:i})}let l=window.location.href,u=Buffer.from(new Y(32).clampUTF8);return await n.set(`sign-last-message`,e),await n.set(`sign-last-nonce`,Array.from(u)),await n.set(`sign-last-url`,l),o({message:e,nonce:u,recipient:i,callbackUrl:l}),new Promise(()=>({}))}}let a=await n.get(`signer-address`),o=await n.get(`signer-public-key`);if(a!==t||!o){n.reset(),await r.client.auth.logoutKGW();let a=Buffer.from(new Y(32).bytes),s=await e.signMessage({message:`idOS authentication`,recipient:i,nonce:a});if(!s)throw Error(`signMessage returned no result`);({publicKey:o}=s),await n.set(`signer-address`,t),await n.set(`signer-public-key`,o)}let s=X(e,i);return{kwilSigner:new l(s,Z(o),`nep413`),publicKey:o}}async function fe(e,t,n,r,i){let a=await n.get(`signer-address`),s=await n.get(`signer-public-key`);if(a!==t||s&&s!==i)try{console.log(`logoutKGW`,r)}catch(e){console.error(`Failed to logout KGW:`,e)}return await n.set(`signer-address`,t),await n.set(`signer-public-key`,i),new l(async t=>{let n=await o(t,e);if(!n||!/^(?:[0-9a-f]{2})+$/i.test(n))throw Error(`Failed to sign transaction with XRP`);return Buffer.from(n,`hex`)},i,`xrpl`)}function pe(e){return typeof e==`object`&&!!e&&`publicKey`in e&&e.publicKey instanceof Uint8Array&&e.publicKey.length===S.sign.publicKeyLength&&`secretKey`in e&&e.secretKey instanceof Uint8Array&&e.secretKey.length===S.sign.secretKeyLength}function $(e){return typeof e==`object`&&!!e&&`getPublicKey`in e&&`sign`in e&&typeof e.getPublicKey==`function`&&typeof e.sign==`function`}function me(e){return typeof e==`object`&&!!e&&`publicKey`in e&&`sign`in e&&`canSign`in e&&typeof e.publicKey==`function`&&typeof e.sign==`function`&&typeof e.canSign==`function`}function he(e){return typeof e==`object`&&!!e&&`publicAddress`in e&&`signatureType`in e&&`publicKey`in e&&`signMessage`in e}function ge(e){return!!e&&typeof e==`object`&&`privateKey`in e&&`publicKey`in e}async function _e(e){if(pe(e))return[new l(async t=>S.sign.detached(t,e.secretKey),e.publicKey,`ed25519`),Z(_(e.publicKey))];if($(e)){let t=e.getPublicKey().toString(),n=Z(t);return[new l(r(`idos-issuer`)(e),n,`nep413`),t]}if(me(e)){let t=e.publicKey(),n=e.rawPublicKey();return[new l(async t=>e.sign(Buffer.from(t)),n,`ed25519`),t]}if(ge(e)){let t;try{t=await import(`ripple-keypairs`)}catch(e){throw Error(`Can't load ripple-keypairs`,{cause:e})}return[new l(async n=>y(t.sign(b(n),e.privateKey)),e.publicKey,`xrpl`),e.publicKey]}return`address`in e?[new l(e,e.address),e.address]:(e=>{throw Error("Invalid `signer` type")})(e)}async function ve(e,n,r){if(`connect`in r&&`address`in r){r=r;let t=await r.getAddress();if(await e.get(`signer-address`)!==t){e.set(`signer-address`,t);try{await n.client.auth.logoutKGW()}catch(e){console.log(`error logoutKGW`,e)}}return[new l(r,t),t,void 0,`EVM`]}if(J(r)){let t=await r.getAccounts(),{kwilSigner:i,publicKey:a}=await de(r,t[0].accountId,e,n);return[i,t[0].accountId,a,`NEAR`]}if(s(r)){let{address:t,publicKey:i}=await a(r);if(!t)throw Error(`Failed to get XRP address`);return[await fe(r,t,e,n,i),t,i,`XRPL`]}if(he(r)||r instanceof t){if(await e.get(`signer-address`)!==r.publicAddress){e.set(`signer-address`,r.publicAddress);try{await n.client.auth.logoutKGW()}catch(e){console.log(`error logoutKGW`,e)}}return[new l(async e=>r.signMessage(e),r.publicAddress,`ed25519`),r.publicAddress,r.publicKey,r.walletType]}return(e=>{throw Error("Invalid `signer` type")})(r)}export{E as KwilActionClient,T as KwilCallError,c as KwilSigner,C as KwilTxFailedError,w as KwilTxPollTimeoutError,ve as createClientKwilSigner,A as createKgwAuthenticatedBlobGateway,j as createKgwAuthenticatedFetch,O as createNodeKwilClient,_e as createServerKwilSigner,k as createWebKwilClient,Q as getNearFullAccessPublicKeys,Z as implicitAddressFromPublicKey,ue as signNearMessage};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|