@hybrd/xmtp 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.
@@ -0,0 +1,91 @@
1
+ import { Signer } from "@xmtp/node-sdk"
2
+ import { createXMTPClient, validateEnvironment } from "../src/client"
3
+ import { revokeOldInstallations } from "./revoke-installations"
4
+
5
+ async function revokeAllInstallations() {
6
+ console.log("šŸ”„ Revoking ALL XMTP Installations")
7
+ console.log("==================================")
8
+
9
+ // Validate environment
10
+ const { XMTP_WALLET_KEY } = validateEnvironment(["XMTP_WALLET_KEY"])
11
+
12
+ if (!XMTP_WALLET_KEY) {
13
+ console.error("āŒ XMTP_WALLET_KEY is required")
14
+ process.exit(1)
15
+ }
16
+
17
+ try {
18
+ console.log(`🌐 Environment: ${process.env.XMTP_ENV || "dev"}`)
19
+
20
+ // Try to create client to get current inbox ID
21
+ try {
22
+ const client = await createXMTPClient(XMTP_WALLET_KEY)
23
+ const currentInboxId = client.inboxId
24
+
25
+ console.log(`šŸ“§ Current Inbox ID: ${currentInboxId}`)
26
+ console.log("šŸ”§ Attempting to revoke all installations for this inbox...")
27
+
28
+ const success = await revokeOldInstallations(
29
+ client.signer as Signer,
30
+ currentInboxId
31
+ )
32
+
33
+ // Create signer
34
+ console.log(`šŸ”‘ Wallet Address: ${client.accountIdentifier?.identifier}`)
35
+
36
+ if (success) {
37
+ console.log("āœ… Successfully revoked all installations")
38
+ } else {
39
+ console.log("āŒ Failed to revoke installations")
40
+ process.exit(1)
41
+ }
42
+ } catch (clientError) {
43
+ console.log(
44
+ "āš ļø Could not create client, attempting alternative approach..."
45
+ )
46
+
47
+ // If we can't create a client, it might be because of installation limits
48
+ // Try to manually construct possible inbox IDs or use a different approach
49
+ console.log("šŸ” This might indicate installation limit issues")
50
+ console.log("šŸ’” You may need to:")
51
+ console.log(" 1. Wait a few minutes and try again")
52
+ console.log(" 2. Use the specific inbox ID if you know it")
53
+ console.log(" 3. Try switching XMTP environments (dev <-> production)")
54
+
55
+ throw clientError
56
+ }
57
+ } catch (error) {
58
+ console.error("šŸ’„ Error revoking installations:", error)
59
+
60
+ if (error instanceof Error) {
61
+ if (error.message.includes("5/5 installations")) {
62
+ console.log("\nšŸ’” Installation limit reached. Possible solutions:")
63
+ console.log(" 1. Wait 24 hours for installations to expire")
64
+ console.log(
65
+ " 2. Try switching XMTP environments (dev <-> production)"
66
+ )
67
+ console.log(" 3. Use a different wallet")
68
+ } else if (error.message.includes("Missing existing member")) {
69
+ console.log(
70
+ "\nšŸ’” This inbox ID may not exist or may be on a different environment"
71
+ )
72
+ console.log(
73
+ " 1. Check if you're using the correct XMTP_ENV (dev vs production)"
74
+ )
75
+ console.log(" 2. Verify the inbox ID is correct")
76
+ }
77
+ }
78
+
79
+ process.exit(1)
80
+ }
81
+ }
82
+
83
+ // Run if called directly
84
+ if (import.meta.url === `file://${process.argv[1]}`) {
85
+ revokeAllInstallations().catch((error) => {
86
+ console.error("šŸ’„ Fatal error:", error)
87
+ process.exit(1)
88
+ })
89
+ }
90
+
91
+ export { revokeAllInstallations }
@@ -0,0 +1,94 @@
1
+ import { Client, Signer, createSigner } from "../src/index"
2
+
3
+ // Function to revoke old installations when hitting the limit
4
+ export async function revokeOldInstallations(signer: Signer, inboxId?: string) {
5
+ console.log("šŸ”§ Attempting to revoke old installations...")
6
+
7
+ try {
8
+ // If we don't have the inboxId, we need to extract it from a temporary client attempt
9
+ if (!inboxId) {
10
+ console.log("ā„¹ļø No inboxId provided, cannot revoke installations")
11
+ return false
12
+ }
13
+
14
+ const inboxStates = await Client.inboxStateFromInboxIds(
15
+ [inboxId],
16
+ process.env.XMTP_ENV as "dev" | "production"
17
+ )
18
+
19
+ if (!inboxStates[0]) {
20
+ console.log("āŒ No inbox state found for the provided inboxId")
21
+ return false
22
+ }
23
+
24
+ const toRevokeInstallationBytes = inboxStates[0].installations.map(
25
+ (i) => i.bytes
26
+ )
27
+
28
+ await Client.revokeInstallations(
29
+ signer,
30
+ inboxId,
31
+ toRevokeInstallationBytes,
32
+ process.env.XMTP_ENV as "dev" | "production"
33
+ )
34
+
35
+ const resultingStates = await Client.inboxStateFromInboxIds(
36
+ [inboxId],
37
+ process.env.XMTP_ENV as "dev" | "production"
38
+ )
39
+
40
+ console.log(
41
+ `šŸ“‹ Revoked installations: ${toRevokeInstallationBytes.length} installations`
42
+ )
43
+ console.log(
44
+ `šŸ“‹ Resulting state: ${resultingStates[0]?.installations.length || 0} installations`
45
+ )
46
+
47
+ return true
48
+ } catch (error) {
49
+ console.error("āŒ Error during installation revocation:", error)
50
+ return false
51
+ }
52
+ }
53
+
54
+ // CLI script to revoke installations
55
+ async function main() {
56
+ const { XMTP_WALLET_KEY } = process.env
57
+ const inboxId = process.argv[2]
58
+
59
+ if (!XMTP_WALLET_KEY) {
60
+ console.error("āŒ XMTP_WALLET_KEY is required")
61
+ process.exit(1)
62
+ }
63
+
64
+ if (!inboxId) {
65
+ console.error("āŒ InboxID is required as CLI argument")
66
+ console.error("Usage: tsx revoke-installations.ts <inboxId>")
67
+ process.exit(1)
68
+ }
69
+
70
+ const signer = createSigner(XMTP_WALLET_KEY)
71
+ const identifier = await signer.getIdentifier()
72
+ const address = identifier.identifier
73
+
74
+ console.log(`šŸ”‘ Wallet Address: ${address}`)
75
+ console.log(`šŸ“‹ Inbox ID: ${inboxId}`)
76
+
77
+ // Try to revoke installations
78
+ const success = await revokeOldInstallations(signer, inboxId)
79
+
80
+ if (success) {
81
+ console.log("āœ… Successfully revoked installations")
82
+ } else {
83
+ console.log("āŒ Failed to revoke installations")
84
+ process.exit(1)
85
+ }
86
+ }
87
+
88
+ // Run if called directly
89
+ if (import.meta.url === `file://${process.argv[1]}`) {
90
+ main().catch((error) => {
91
+ console.error("šŸ’„ Fatal error:", error)
92
+ process.exit(1)
93
+ })
94
+ }