#Share Asset

Share an asset with another user with granular permissions control. The recipient gets access based on the permissions you grant (read, write, admin).

#Method Signature

shareAsset(
  assetId: string,
  grantedTo: string,
  options?: {
    canRead?: boolean;
    canWrite?: boolean;
    canAdmin?: boolean;
    expiresAt?: number;
    passwordHash?: string;
  }
): Promise<void>
typescript

#Parameters

#assetId (required)

The ID of the asset to share.

  • Type: string
  • Format: Sui object ID (0x...)

#grantedTo (required)

The wallet address of the recipient.

  • Type: string
  • Format: Sui address (0x...)

#options (optional)

#canRead

  • Type: boolean
  • Default: true
  • Allows recipient to read/download the asset

#canWrite

  • Type: boolean
  • Default: false
  • Allows recipient to modify the asset

#canAdmin

  • Type: boolean
  • Default: false
  • Grants full administrative access including sharing

#expiresAt

  • Type: number
  • Optional
  • Expiration timestamp in milliseconds

#passwordHash

  • Type: string
  • Optional
  • Hash of password required to access the asset

#Returns

Promise<void> - Resolves when share is created

#Examples

#Basic Share (Read-Only)

// Grant read-only access
await walbucket.shareAsset(
  assetId,
  '0x789...' // recipient address
);
typescript

#Share with Write Permission

// Grant read and write access
await walbucket.shareAsset(assetId, recipientAddress, {
  canRead: true,
  canWrite: true
});
typescript

#Share with Admin Permission

// Grant full admin access
await walbucket.shareAsset(assetId, recipientAddress, {
  canRead: true,
  canWrite: true,
  canAdmin: true
});
typescript

#Time-Limited Share

// Share for 7 days
const expiresAt = Date.now() + (7 * 24 * 60 * 60 * 1000);
await walbucket.shareAsset(assetId, recipientAddress, {
  canRead: true,
  expiresAt
});
typescript

#Password-Protected Share

import { createHash } from 'crypto';

// Create password hash
const password = 'secure-password-123';
const passwordHash = createHash('sha256').update(password).digest('hex');

await walbucket.shareAsset(assetId, recipientAddress, {
  canRead: true,
  passwordHash
});
typescript

#Share with Multiple Users

const team = [
  { address: '0x111...', role: 'viewer' },
  { address: '0x222...', role: 'editor' },
  { address: '0x333...', role: 'admin' }
];

for (const member of team) {
  await walbucket.shareAsset(assetId, member.address, {
    canRead: true,
    canWrite: member.role !== 'viewer',
    canAdmin: member.role === 'admin'
  });
}
typescript

#Share with Notification

async function shareWithNotification(
  assetId: string,
  recipientAddress: string,
  assetName: string
) {
  try {
    await walbucket.shareAsset(assetId, recipientAddress, {
      canRead: true
    });

    // Send notification to recipient
    await sendEmail(recipientAddress, {
      subject: 'New file shared with you',
      body: `${assetName} has been shared with you`
    });
  } catch (error) {
    console.error('Failed to share:', error);
    throw error;
  }
}
typescript

#Permission Levels

#Read-Only Access

{ canRead: true, canWrite: false, canAdmin: false }
typescript
  • View and download the asset
  • Cannot modify or share

#Editor Access

{ canRead: true, canWrite: true, canAdmin: false }
typescript
  • View, download, and modify
  • Cannot share with others

#Admin Access

{ canRead: true, canWrite: true, canAdmin: true }
typescript
  • Full access including sharing
  • Can grant access to others

#How Sharing Works

  1. Access Grant: Creates an on-chain access grant
  2. Permission Control: Recipient gets specified permissions
  3. Blockchain Verified: Access enforced by smart contract
  4. Revocable: Can be revoked at any time using revokeShare()
  5. Query-able: Use listAccessGrants() to see all shares

#Error Handling

try {
  await walbucket.shareAsset(assetId, recipient, options);
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Invalid asset ID or recipient address');
  } else if (error instanceof BlockchainError) {
    if (error.message.includes('E_NOT_OWNER')) {
      console.error('You do not own this asset');
    } else if (error.message.includes('already granted')) {
      console.error('Asset already shared with this user');
    } else {
      console.error('Blockchain error:', error.message);
    }
  }
}
typescript

#Notes

  • Only asset owner can create shares
  • Each share creates an on-chain access grant
  • Gas fees apply based on gasStrategy
  • Recipients don't need special setup to receive access
  • Multiple grants can exist per asset
  • Use listAccessGrants() to view all active shares

#Use Cases

#Team Collaboration

// Share design files with read access
await walbucket.shareAsset(designFileId, designerAddress, {
  canRead: true
});

// Share documents with edit access
await walbucket.shareAsset(documentId, writerAddress, {
  canRead: true,
  canWrite: true
});
typescript

#Client Access

// Share deliverables with clients
await walbucket.shareAsset(deliverableId, clientAddress, {
  canRead: true,
  expiresAt: Date.now() + (30 * 24 * 60 * 60 * 1000) // 30 days
});
typescript

#Temporary Collaboration

// Grant temporary access for review
const expiresAt = Date.now() + (48 * 60 * 60 * 1000); // 48 hours
await walbucket.shareAsset(draftId, reviewerAddress, {
  canRead: true,
  canWrite: true,
  expiresAt
});
typescript