@yeying-community/web3-bs 1.0.15 → 1.0.16

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.
@@ -4,7 +4,8 @@
4
4
  * 调用钱包插件的 `yeying_encrypt` / `yeying_decrypt` / `yeying_getCipherSuites`
5
5
  * EIP-1193 自定义方法。命名安全套件 + 静默执行 + 站点授权模型同 UCAN。
6
6
  *
7
- * 数据密码(password 参数)由 DApp 自行管理与钱包密码独立;
7
+ * 默认数据密码(password 参数)由 DApp 自行管理与钱包密码独立;
8
+ * 也可通过 passwordSource 请求钱包插件在钱包内部派生加密密码。
8
9
  * plaintext 走 base64 字符串跨 message 边界传输。
9
10
  */
10
11
  import { isUserRejectedWalletAction } from './provider';
@@ -14,15 +15,20 @@ export interface CipherSuiteInfo {
14
15
  description: string;
15
16
  mode: 'hash' | 'symmetric';
16
17
  }
18
+ export type CipherPasswordSource = 'manual' | 'wallet' | 'wallet+password';
17
19
  export interface EncryptOptions {
18
20
  data: string | Uint8Array;
19
- password: string;
21
+ password?: string;
22
+ passwordSource?: CipherPasswordSource;
23
+ passwordContext?: string;
20
24
  suite?: string;
21
25
  provider?: Eip1193Provider;
22
26
  }
23
27
  export interface DecryptOptions {
24
28
  ciphertext: string;
25
- password: string;
29
+ password?: string;
30
+ passwordSource?: CipherPasswordSource;
31
+ passwordContext?: string;
26
32
  provider?: Eip1193Provider;
27
33
  }
28
34
  export interface GetCipherSuitesOptions {
@@ -2036,7 +2036,8 @@ async function authCentralUcanFetch(input, init = {}, options = {}) {
2036
2036
  * 调用钱包插件的 `yeying_encrypt` / `yeying_decrypt` / `yeying_getCipherSuites`
2037
2037
  * EIP-1193 自定义方法。命名安全套件 + 静默执行 + 站点授权模型同 UCAN。
2038
2038
  *
2039
- * 数据密码(password 参数)由 DApp 自行管理与钱包密码独立;
2039
+ * 默认数据密码(password 参数)由 DApp 自行管理与钱包密码独立;
2040
+ * 也可通过 passwordSource 请求钱包插件在钱包内部派生加密密码。
2040
2041
  * plaintext 走 base64 字符串跨 message 边界传输。
2041
2042
  */
2042
2043
  class CipherError extends Error {
@@ -2087,6 +2088,8 @@ async function encrypt(options) {
2087
2088
  params: [{
2088
2089
  data: options.data,
2089
2090
  password: options.password,
2091
+ passwordSource: options.passwordSource,
2092
+ passwordContext: options.passwordContext,
2090
2093
  suite: options.suite
2091
2094
  }]
2092
2095
  });
@@ -2110,7 +2113,9 @@ async function decrypt(options) {
2110
2113
  method: 'yeying_decrypt',
2111
2114
  params: [{
2112
2115
  ciphertext: options.ciphertext,
2113
- password: options.password
2116
+ password: options.password,
2117
+ passwordSource: options.passwordSource,
2118
+ passwordContext: options.passwordContext
2114
2119
  }]
2115
2120
  });
2116
2121
  if (!result || typeof result !== 'object' || typeof result.plaintext !== 'string') {