#Revoke Share
Revoke a previously granted access grant. The recipient will immediately lose access to the asset.
#Method Signature
revokeShare(grantId: string): Promise<void>typescript
#Parameters
#grantId (required)
The ID of the AccessGrant to revoke.
- Type:
string - Format: Sui object ID (0x...)
- Obtained from
listAccessGrants()or when creating the share
#Returns
Promise<void> - Resolves when share is revoked
#Examples
#Basic Revoke
// Revoke an access grant
await walbucket.revokeShare(grantId);
console.log('Access revoked successfully');typescript
#Revoke with Confirmation
async function revokeWithConfirmation(
grantId: string,
recipientAddress: string
) {
if (confirm(`Revoke access for ${recipientAddress}?`)) {
try {
await walbucket.revokeShare(grantId);
alert('Access revoked successfully');
} catch (error) {
alert(`Failed to revoke: ${error.message}`);
}
}
}typescript
#Revoke All Grants for an Asset
async function revokeAllAccess(assetId: string) {
// Get all grants for the asset
const allGrants = await walbucket.listAccessGrants();
const assetGrants = allGrants.filter(grant =>
grant.assetId === assetId
);
if (assetGrants.length === 0) {
console.log('No grants to revoke');
return;
}
// Revoke each grant
for (const grant of assetGrants) {
await walbucket.revokeShare(grant.id);
console.log(`Revoked grant: ${grant.id}`);
}
console.log(`Revoked ${assetGrants.length} grants`);
}typescript
#Revoke Specific User Access
async function revokeUserAccess(assetId: string, userAddress: string) {
const grants = await walbucket.listAccessGrants();
const userGrant = grants.find(grant =>
grant.assetId === assetId && grant.grantedTo === userAddress
);
if (userGrant) {
await walbucket.revokeShare(userGrant.id);
console.log(`Revoked access for ${userAddress}`);
} else {
console.log('No grant found for this user');
}
}typescript
#Time-Limited Auto-Revoke
async function shareTemporarily(
assetId: string,
recipient: string,
durationMs: number
) {
// Create share
await walbucket.shareAsset(assetId, recipient, {
canRead: true
});
// Get the grant ID (you need to track this or query)
const grants = await walbucket.listAccessGrants();
const grant = grants.find(g =>
g.assetId === assetId && g.grantedTo === recipient
);
if (!grant) {
throw new Error('Grant not found');
}
console.log('Access granted temporarily');
// Auto-revoke after duration
setTimeout(async () => {
await walbucket.revokeShare(grant.id);
console.log('Access revoked automatically');
}, durationMs);
return grant.id;
}
// Usage: 24-hour access
await shareTemporarily(assetId, recipientAddress, 24 * 60 * 60 * 1000);typescript
#Batch Revoke
async function batchRevokeGrants(grantIds: string[]) {
const results = [];
for (const grantId of grantIds) {
try {
await walbucket.revokeShare(grantId);
results.push({ grantId, status: 'success' });
} catch (error) {
results.push({
grantId,
status: 'failed',
error: error.message
});
}
}
return results;
}typescript
#Revoke UI Component
async function renderShareManagement(assetId: string) {
const grants = await walbucket.listAccessGrants();
const assetGrants = grants.filter(g => g.assetId === assetId);
return (
<div>
<h3>Active Shares</h3>
{assetGrants.map(grant => (
<div key={grant.id}>
<span>{grant.grantedTo}</span>
<span>
Permissions:
{grant.canRead && ' Read'}
{grant.canWrite && ' Write'}
{grant.canAdmin && ' Admin'}
</span>
{grant.expiresAt && (
<span>Expires: {new Date(grant.expiresAt).toLocaleString()}</span>
)}
<button onClick={() => handleRevoke(grant.id)}>
Revoke
</button>
</div>
))}
</div>
);
}
async function handleRevoke(grantId: string) {
await walbucket.revokeShare(grantId);
// Refresh UI
}typescript
#What Happens When You Revoke
- Grant Deleted: The access grant is removed from blockchain
- Access Removed: Recipient immediately loses all permissions
- Immediate Effect: Takes effect instantly
- Permanent: Cannot be undone (must create new share if needed)
- Owner Unaffected: Owner retains full access
#Error Handling
try {
await walbucket.revokeShare(grantId);
} catch (error) {
if (error instanceof ValidationError) {
console.error('Invalid grant ID');
} else if (error instanceof BlockchainError) {
if (error.message.includes('E_NOT_OWNER')) {
console.error('You do not own this grant');
} else if (error.message.includes('not found')) {
console.error('Grant not found (may already be revoked)');
} else if (error.message.includes('E_ASSET_DELETED')) {
console.error('Asset has been deleted');
} else {
console.error('Blockchain error:', error.message);
}
}
}typescript
#Notes
- Only grant creator (asset owner) can revoke
- Revocation is immediate and permanent
- Does not delete the asset itself
- Gas fees apply based on
gasStrategy - Multiple grants can exist (revoke individually)
- Use
listAccessGrants()to view all active grants
#Use Cases
#Security Response
// Immediately revoke all access in case of security incident
async function emergencyLockdown(assetId: string) {
const grants = await walbucket.listAccessGrants();
const assetGrants = grants.filter(g => g.assetId === assetId);
for (const grant of assetGrants) {
await walbucket.revokeShare(grant.id);
}
console.log(`Emergency: Revoked ${assetGrants.length} grants`);
}typescript
#Team Member Removal
// Revoke all access when team member leaves
async function removeTeamMember(memberAddress: string) {
const grants = await walbucket.listAccessGrants();
const memberGrants = grants.filter(g => g.grantedTo === memberAddress);
for (const grant of memberGrants) {
await walbucket.revokeShare(grant.id);
}
console.log(`Removed access for ${memberAddress}`);
}typescript
#Conditional Revocation
// Revoke expired grants (if not using blockchain expiration)
async function cleanupExpiredGrants() {
const grants = await walbucket.listAccessGrants();
const now = Date.now();
for (const grant of grants) {
// Custom expiration logic
const created = new Date(grant.createdAt).getTime();
if (created + (30 * 24 * 60 * 60 * 1000) < now) {
await walbucket.revokeShare(grant.id);
console.log(`Cleaned up expired grant: ${grant.id}`);
}
}
}typescript
#Best Practices
- Track Grant IDs: Store grant IDs when creating shares for easy revocation
- Audit Trail: Log all revocations for compliance and security audit
- User Notification: Notify users when their access is revoked
- Confirmation: Require user confirmation before revoking
- Batch Operations: Handle multiple revocations efficiently
#Related
- Share Asset - Create access grants
- List Access Grants - View all grants
- Deactivate Shareable Link - Disable public links
- Create Shareable Link - Create public links