@bsv/btms-permission-module 1.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/src/index.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * BTMS Permission Module (Core)
3
+ *
4
+ * Provides wallet permission module for BTMS token spending authorization.
5
+ * This is the core module without UI dependencies - framework agnostic.
6
+ *
7
+ * For React/MUI UI components, see @bsv/btms-permission-module-ui
8
+ */
9
+
10
+ import type { WalletInterface } from '@bsv/sdk'
11
+ import { BTMS } from '@bsv/btms'
12
+ import { BasicTokenModule } from './BasicTokenModule.js'
13
+
14
+ export type PermissionPromptHandler = (app: string, message: string) => Promise<boolean>
15
+
16
+ export type PermissionModuleFactoryArgs = {
17
+ wallet: WalletInterface
18
+ promptHandler?: PermissionPromptHandler
19
+ }
20
+
21
+ const denyPrompt: PermissionPromptHandler = async () => false
22
+
23
+ export const createBtmsModule = ({ wallet, promptHandler }: PermissionModuleFactoryArgs) => {
24
+ const btms = new BTMS({ wallet, networkPreset: 'local' })
25
+ return new BasicTokenModule(promptHandler ?? denyPrompt, btms)
26
+ }
27
+
28
+ export { BasicTokenModule }
package/src/types.ts ADDED
@@ -0,0 +1,81 @@
1
+ // ---------------------------------------------------------------------------
2
+ // BTMS Permission Module Constants and Types
3
+ // ---------------------------------------------------------------------------
4
+ // BRC-99: Baskets prefixed with "p " are permissioned and require wallet
5
+ // permission module support. The scheme ID is "btms".
6
+ //
7
+ // Token basket format: "p btms <assetId>"
8
+ // Example: "p btms abc123def456.0"
9
+ // ---------------------------------------------------------------------------
10
+
11
+ /** Permissioned basket prefix - aligns with btms-core */
12
+ export const P_BASKET_PREFIX = 'p btms'
13
+
14
+ /** Literal used in field[0] to indicate token issuance - aligns with btms-core */
15
+ export const ISSUE_MARKER = 'ISSUE'
16
+
17
+ /** Index positions for BTMS PushDrop token fields */
18
+ export const BTMS_FIELD = {
19
+ ASSET_ID: 0,
20
+ AMOUNT: 1,
21
+ METADATA: 2
22
+ } as const
23
+
24
+ /**
25
+ * Parsed information about a BTMS token from its locking script
26
+ */
27
+ export interface ParsedTokenInfo {
28
+ assetId: string
29
+ amount: number
30
+ metadata?: {
31
+ name?: string
32
+ description?: string
33
+ iconURL?: string
34
+ [key: string]: unknown
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Comprehensive token spend information extracted from createAction args
40
+ */
41
+ export interface TokenSpendInfo {
42
+ /** Total amount being sent to recipient (not including change) */
43
+ sendAmount: number
44
+ /** Total amount being spent from inputs */
45
+ totalInputAmount: number
46
+ /** Change amount (totalInputAmount - sendAmount) */
47
+ changeAmount: number
48
+ /** Total amount sent in token outputs (derived from outputs) */
49
+ outputSendAmount: number
50
+ /** Total amount returned as change in token outputs (derived from outputs) */
51
+ outputChangeAmount: number
52
+ /** Whether any token outputs were parsed */
53
+ hasTokenOutputs: boolean
54
+ /** Source of totalInputAmount */
55
+ inputAmountSource: 'beef' | 'descriptions' | 'derived' | 'none'
56
+ /** Token name from metadata */
57
+ tokenName: string
58
+ /** Asset ID */
59
+ assetId: string
60
+ /** Recipient identity key (truncated) */
61
+ recipient?: string
62
+ /** Token icon URL if available */
63
+ iconURL?: string
64
+ /** Full action description */
65
+ actionDescription: string
66
+ }
67
+
68
+ /**
69
+ * Authorized transaction data captured from createAction response.
70
+ * Used to verify createSignature calls are signing what was actually authorized.
71
+ */
72
+ export interface AuthorizedTransaction {
73
+ /** The reference from the signable transaction */
74
+ reference: string
75
+ /** Hash of all outputs (BIP-143 hashOutputs) */
76
+ hashOutputs: string
77
+ /** Set of authorized outpoints (txid.vout format) */
78
+ authorizedOutpoints: Set<string>
79
+ /** Timestamp when this authorization was created */
80
+ timestamp: number
81
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "moduleResolution": "node",
6
+ "lib": [
7
+ "ES2022"
8
+ ],
9
+ "outDir": "./dist",
10
+ "rootDir": "./src",
11
+ "declaration": true,
12
+ "declarationMap": true,
13
+ "esModuleInterop": true,
14
+ "skipLibCheck": true,
15
+ "strict": true,
16
+ "resolveJsonModule": true,
17
+ "allowSyntheticDefaultImports": true
18
+ },
19
+ "include": [
20
+ "src/**/*"
21
+ ],
22
+ "exclude": [
23
+ "node_modules",
24
+ "dist",
25
+ "ui"
26
+ ]
27
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/basictokenmodule.ts","./src/index.ts","./src/types.ts"],"version":"5.9.3"}