@miden-sdk/miden-wallet-adapter-base 0.13.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.
Files changed (104) hide show
  1. package/adapter.ts +146 -0
  2. package/dist/adapter.d.ts +69 -0
  3. package/dist/adapter.js +74 -0
  4. package/dist/adapter.js.map +1 -0
  5. package/dist/errors.d.ts +70 -0
  6. package/dist/errors.js +75 -0
  7. package/dist/errors.js.map +1 -0
  8. package/dist/helpers.d.ts +2 -0
  9. package/dist/helpers.js +32 -0
  10. package/dist/helpers.js.map +1 -0
  11. package/dist/index.d.ts +6 -0
  12. package/dist/index.js +7 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/signer.d.ts +34 -0
  15. package/dist/signer.js +6 -0
  16. package/dist/signer.js.map +1 -0
  17. package/dist/transaction.d.ts +67 -0
  18. package/dist/transaction.js +74 -0
  19. package/dist/transaction.js.map +1 -0
  20. package/dist/types.d.ts +47 -0
  21. package/dist/types.js +19 -0
  22. package/dist/types.js.map +1 -0
  23. package/docs/@miden-sdk/namespaces/EventEmitter/README.md +24 -0
  24. package/docs/@miden-sdk/namespaces/EventEmitter/interfaces/EventEmitterStatic.md +17 -0
  25. package/docs/@miden-sdk/namespaces/EventEmitter/interfaces/ListenerFn.md +25 -0
  26. package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/ArgumentMap.md +15 -0
  27. package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/EventArgs.md +19 -0
  28. package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/EventListener.md +19 -0
  29. package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/EventNames.md +15 -0
  30. package/docs/@miden-sdk/namespaces/EventEmitter/type-aliases/ValidEventTypes.md +17 -0
  31. package/docs/@miden-sdk/namespaces/EventEmitter/variables/EventEmitter.md +9 -0
  32. package/docs/README.md +88 -0
  33. package/docs/classes/BaseMessageSignerWalletAdapter.md +755 -0
  34. package/docs/classes/BaseSignerWalletAdapter.md +579 -0
  35. package/docs/classes/BaseWalletAdapter.md +535 -0
  36. package/docs/classes/ConsumeTransaction.md +93 -0
  37. package/docs/classes/CustomTransaction.md +93 -0
  38. package/docs/classes/EventEmitter.md +305 -0
  39. package/docs/classes/SendTransaction.md +107 -0
  40. package/docs/classes/Transaction.md +151 -0
  41. package/docs/classes/WalletAccountError.md +223 -0
  42. package/docs/classes/WalletAddressError.md +223 -0
  43. package/docs/classes/WalletConfigError.md +223 -0
  44. package/docs/classes/WalletConnectionError.md +223 -0
  45. package/docs/classes/WalletDecryptionError.md +223 -0
  46. package/docs/classes/WalletDecryptionNotAllowedError.md +223 -0
  47. package/docs/classes/WalletDisconnectedError.md +223 -0
  48. package/docs/classes/WalletDisconnectionError.md +223 -0
  49. package/docs/classes/WalletError.md +244 -0
  50. package/docs/classes/WalletKeypairError.md +223 -0
  51. package/docs/classes/WalletLoadError.md +223 -0
  52. package/docs/classes/WalletNotConnectedError.md +223 -0
  53. package/docs/classes/WalletNotReadyError.md +223 -0
  54. package/docs/classes/WalletNotSelectedError.md +223 -0
  55. package/docs/classes/WalletPrivateDataPermissionError.md +223 -0
  56. package/docs/classes/WalletRecordsError.md +223 -0
  57. package/docs/classes/WalletSendTransactionError.md +223 -0
  58. package/docs/classes/WalletSignMessageError.md +223 -0
  59. package/docs/classes/WalletSignTransactionError.md +223 -0
  60. package/docs/classes/WalletTimeoutError.md +223 -0
  61. package/docs/classes/WalletTransactionError.md +223 -0
  62. package/docs/classes/WalletWindowBlockedError.md +223 -0
  63. package/docs/classes/WalletWindowClosedError.md +223 -0
  64. package/docs/enumerations/AllowedPrivateData.md +37 -0
  65. package/docs/enumerations/PrivateDataPermission.md +19 -0
  66. package/docs/enumerations/TransactionType.md +25 -0
  67. package/docs/enumerations/WalletAdapterNetwork.md +19 -0
  68. package/docs/enumerations/WalletReadyState.md +49 -0
  69. package/docs/functions/b64ToU8.md +19 -0
  70. package/docs/functions/scopePollingDetectionStrategy.md +19 -0
  71. package/docs/functions/u8ToB64.md +19 -0
  72. package/docs/interfaces/Asset.md +19 -0
  73. package/docs/interfaces/IFailedTransactionOutput.md +13 -0
  74. package/docs/interfaces/MessageSignerWalletAdapterProps.md +293 -0
  75. package/docs/interfaces/MidenConsumeTransaction.md +37 -0
  76. package/docs/interfaces/MidenCustomTransaction.md +37 -0
  77. package/docs/interfaces/MidenSendTransaction.md +43 -0
  78. package/docs/interfaces/MidenTransaction.md +19 -0
  79. package/docs/interfaces/SignerWalletAdapterProps.md +149 -0
  80. package/docs/interfaces/TransactionOutput.md +19 -0
  81. package/docs/interfaces/WalletAdapterEvents.md +69 -0
  82. package/docs/interfaces/WalletAdapterProps.md +106 -0
  83. package/docs/interfaces/WalletTransactionSuccessOutput.md +19 -0
  84. package/docs/type-aliases/Adapter.md +9 -0
  85. package/docs/type-aliases/FungibleAssetDetails.md +21 -0
  86. package/docs/type-aliases/InputNoteDetails.md +45 -0
  87. package/docs/type-aliases/MessageSignerWalletAdapter.md +15 -0
  88. package/docs/type-aliases/NoteTypeString.md +9 -0
  89. package/docs/type-aliases/SignKind.md +9 -0
  90. package/docs/type-aliases/SignerWalletAdapter.md +15 -0
  91. package/docs/type-aliases/SupportedTransactionVersions.md +9 -0
  92. package/docs/type-aliases/TransactionOrVersionedTransaction.md +15 -0
  93. package/docs/type-aliases/TransactionPayload.md +9 -0
  94. package/docs/type-aliases/WalletAdapter.md +15 -0
  95. package/docs/type-aliases/WalletName.md +21 -0
  96. package/docs/type-aliases/WalletTransactionOutput.md +9 -0
  97. package/errors.ts +97 -0
  98. package/helpers.ts +28 -0
  99. package/index.ts +6 -0
  100. package/package.json +21 -0
  101. package/signer.ts +71 -0
  102. package/transaction.ts +178 -0
  103. package/tsconfig.json +15 -0
  104. package/types.ts +68 -0
package/transaction.ts ADDED
@@ -0,0 +1,178 @@
1
+ import type { TransactionRequest } from '@miden-sdk/miden-sdk';
2
+ import { u8ToB64 } from './helpers';
3
+
4
+ export type NoteTypeString = 'public' | 'private';
5
+
6
+ export interface MidenSendTransaction {
7
+ senderAddress: string;
8
+ recipientAddress: string;
9
+ faucetId: string;
10
+ noteType: NoteTypeString;
11
+ amount: number;
12
+ recallBlocks?: number;
13
+ }
14
+
15
+ export class SendTransaction implements MidenSendTransaction {
16
+ senderAddress: string;
17
+ recipientAddress: string;
18
+ faucetId: string;
19
+ noteType: NoteTypeString;
20
+ amount: number;
21
+ recallBlocks?: number;
22
+
23
+ constructor(
24
+ sender: string,
25
+ recipient: string,
26
+ faucetId: string,
27
+ noteType: NoteTypeString,
28
+ amount: number,
29
+ recallBlocks?: number
30
+ ) {
31
+ this.senderAddress = sender;
32
+ this.recipientAddress = recipient;
33
+ this.faucetId = faucetId;
34
+ this.noteType = noteType;
35
+ this.amount = amount;
36
+ this.recallBlocks = recallBlocks;
37
+ }
38
+ }
39
+
40
+ export interface MidenConsumeTransaction {
41
+ faucetId: string;
42
+ noteId: string;
43
+ noteType: NoteTypeString;
44
+ amount: number;
45
+ noteBytes?: string;
46
+ }
47
+
48
+ export class ConsumeTransaction implements MidenConsumeTransaction {
49
+ faucetId: string;
50
+ noteId: string;
51
+ noteType: NoteTypeString;
52
+ amount: number;
53
+ noteBytes?: string;
54
+
55
+ constructor(
56
+ faucetId: string,
57
+ noteId: string,
58
+ noteType: NoteTypeString,
59
+ amount: number,
60
+ noteBytes?: Uint8Array
61
+ ) {
62
+ this.faucetId = faucetId;
63
+ this.noteId = noteId;
64
+ this.noteType = noteType;
65
+ this.amount = amount;
66
+ this.noteBytes = noteBytes ? u8ToB64(noteBytes) : undefined;
67
+ }
68
+ }
69
+
70
+ export interface MidenCustomTransaction {
71
+ address: string;
72
+ recipientAddress: string;
73
+ transactionRequest: string;
74
+ inputNoteIds?: string[];
75
+ importNotes?: string[];
76
+ }
77
+
78
+ export class CustomTransaction implements MidenCustomTransaction {
79
+ address: string;
80
+ recipientAddress: string;
81
+ transactionRequest: string;
82
+ inputNoteIds?: string[];
83
+ importNotes?: string[];
84
+
85
+ constructor(
86
+ address: string,
87
+ recipientAddress: string,
88
+ transactionRequest: TransactionRequest,
89
+ inputNotesIds?: string[],
90
+ inputNoteBytes?: Uint8Array[]
91
+ ) {
92
+ this.address = address;
93
+ this.recipientAddress = recipientAddress;
94
+ const requestBytes = transactionRequest.serialize();
95
+ const base64 = u8ToB64(requestBytes);
96
+ this.transactionRequest = base64;
97
+ this.inputNoteIds = inputNotesIds;
98
+ this.importNotes = inputNoteBytes?.map((note) => u8ToB64(note));
99
+ }
100
+ }
101
+
102
+ export enum TransactionType {
103
+ Send = 'send',
104
+ Consume = 'consume',
105
+ Custom = 'custom',
106
+ }
107
+ export type TransactionPayload =
108
+ | MidenSendTransaction
109
+ | MidenConsumeTransaction
110
+ | MidenCustomTransaction;
111
+
112
+ export interface MidenTransaction {
113
+ type: TransactionType;
114
+ payload: TransactionPayload;
115
+ }
116
+
117
+ export class Transaction implements MidenTransaction {
118
+ type: TransactionType;
119
+ payload: TransactionPayload;
120
+
121
+ constructor(type: TransactionType, payload: TransactionPayload) {
122
+ this.type = type;
123
+ this.payload = payload;
124
+ }
125
+
126
+ static createSendTransaction(
127
+ sender: string,
128
+ recipient: string,
129
+ faucetId: string,
130
+ noteType: NoteTypeString,
131
+ amount: number,
132
+ recallBlocks?: number
133
+ ) {
134
+ const sendTransaction = new SendTransaction(
135
+ sender,
136
+ recipient,
137
+ faucetId,
138
+ noteType,
139
+ amount,
140
+ recallBlocks
141
+ );
142
+ return new Transaction(TransactionType.Send, sendTransaction);
143
+ }
144
+
145
+ static createConsumeTransaction(
146
+ faucetId: string,
147
+ noteId: string,
148
+ noteType: NoteTypeString,
149
+ amount: number,
150
+ noteBytes?: Uint8Array
151
+ ) {
152
+ const consumeTransaction = new ConsumeTransaction(
153
+ faucetId,
154
+ noteId,
155
+ noteType,
156
+ amount,
157
+ noteBytes
158
+ );
159
+ return new Transaction(TransactionType.Consume, consumeTransaction);
160
+ }
161
+
162
+ static createCustomTransaction(
163
+ address: string,
164
+ recipientAddress: string,
165
+ transactionRequest: TransactionRequest,
166
+ inputNoteIds?: string[],
167
+ noteBytes?: Uint8Array[]
168
+ ) {
169
+ const transactionBytes = new CustomTransaction(
170
+ address,
171
+ recipientAddress,
172
+ transactionRequest,
173
+ inputNoteIds,
174
+ noteBytes
175
+ );
176
+ return new Transaction(TransactionType.Custom, transactionBytes);
177
+ }
178
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "declaration": true,
6
+ "outDir": "dist",
7
+ "sourceMap": true,
8
+ "moduleResolution": "node",
9
+ "esModuleInterop": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "allowSyntheticDefaultImports": true,
12
+ "skipLibCheck": true
13
+ },
14
+ "exclude": ["node_modules", "dist"]
15
+ }
package/types.ts ADDED
@@ -0,0 +1,68 @@
1
+ import type { InputNoteState, Note, NoteType } from '@miden-sdk/miden-sdk';
2
+
3
+ export enum WalletAdapterNetwork {
4
+ Testnet = 'testnet',
5
+ Localnet = 'localnet',
6
+ }
7
+
8
+ export type SupportedTransactionVersions = ReadonlySet<any> | null;
9
+
10
+ export type TransactionOrVersionedTransaction<
11
+ S extends SupportedTransactionVersions
12
+ > = S extends null ? any : any | any;
13
+
14
+ export enum PrivateDataPermission {
15
+ UponRequest = 'UPON_REQUEST', // The App must ask for permission to access private data every time
16
+ Auto = 'AUTO', // The App can access private data without confirmation
17
+ }
18
+
19
+ export enum AllowedPrivateData {
20
+ None = 0,
21
+ Assets = 1 << 0, // 1
22
+ Notes = 1 << 1, // 2
23
+ Storage = 1 << 2, // 4
24
+ All = (1 << 16) - 1, // 65535 (allows for new permissions without requiring a migration)
25
+ }
26
+
27
+ export type SignKind = 'word' | 'signingInputs';
28
+
29
+ export interface Asset {
30
+ faucetId: string;
31
+ amount: string;
32
+ }
33
+
34
+ export type InputNoteDetails = {
35
+ noteId: string;
36
+ senderAccountId: string | undefined;
37
+ assets: FungibleAssetDetails[];
38
+ noteType: NoteType | undefined;
39
+ nullifier: string;
40
+ state: InputNoteState;
41
+ };
42
+
43
+ export type FungibleAssetDetails = {
44
+ amount: string;
45
+ faucetId: string;
46
+ };
47
+
48
+ // Developer-facing transaction output interface
49
+ // Errors from the wallet are thrown as exceptions
50
+ export interface TransactionOutput {
51
+ txHash: string;
52
+ outputNotes: Note[];
53
+ }
54
+
55
+ export interface IFailedTransactionOutput {
56
+ errorMessage: string;
57
+ }
58
+
59
+ // Internal wallet response format - uses serialized note data (string[])
60
+ // Converted to Note objects for the public API (TransactionOutput)
61
+ export interface WalletTransactionSuccessOutput {
62
+ txHash: string;
63
+ outputNotes: string[];
64
+ }
65
+
66
+ export type WalletTransactionOutput =
67
+ | WalletTransactionSuccessOutput
68
+ | IFailedTransactionOutput;