πŸ†”
ID++ SDK Docs
  • πŸ†”Introduction
  • ❓Why use the ID++ SDK?
  • πŸ’‘Key concepts
    • ℹ️Decentralized Web Node (DWN)
    • ℹ️Decentralized identities (DID)
    • ℹ️Schemas
    • ℹ️Records
  • πŸ€“Reference
    • βš™οΈInstallation
    • βš™οΈConfiguration
    • βš™οΈInitialization
    • πŸ“ƒRecords
      • πŸ“–Queries
        • πŸ“‘How to query records
      • βš’οΈCRUD Operations
        • πŸ†•Create a record
        • πŸ“šRead a record
        • πŸ“‘Update a record
        • ❌Delete a record
    • πŸ›‘οΈVerifiable Credentials
      • πŸ’³Credentials
      • πŸ“œPresentations
  • πŸ—ΊοΈGuides
    • πŸ“Handling files
    • πŸš€Sharing records
Powered by GitBook
On this page
  • Create a DID for Alice
  • Create a Protocol
  • Configure Protocol
  • Create a Message from Alice to Bob
  • Reading a Message to Bob from Alice
  1. Guides

Sharing records

  • Use a configured protocol

  • Create the message record

  • Send the message record to recipients

  • Reading the message record from an author

Create a DID for Alice

const alice = await sdk.did.create({
  sync: 'off' | '10s'
});

Create a Protocol

const protocolDef = {
  'protocol'  : 'https://message.xyz/protocol',
  'published' : true,
  'types'     : {
    'message': {
      'schema'      : 'https://message.xyz/protocol/schema',
      'dataFormats' : [
        'application/json'
      ]
    }
  },
  'structure': {
    'message': {
      '$actions': [
        {
          'who' : 'anyone',
          'can' : 'write'
        },
        {
          'who' : 'author',
          'of'  : 'message',
          'can' : 'read'
        },
        {
          'who' : 'recipient',
          'of'  : 'message',
          'can' : 'read'
        }
      ]
    }
  }
}    

Configure Protocol

const { status: configureStatus, protocol } = await sdk.dwn.protocols.configure({
  message: {
    definition: protocolDef
  }
});
console.log('configure protocol local status', configureStatus);

Create a Message from Alice to Bob

const { record, status } = await sdk.dwn.records.create({
  data,
  message : {
    protocol,
    protocolPath,
    schema,
    recipient: did:ion:bob
  }
});

if (status.code !== 202) {
  console.error(`${status.code} - ${status.detail}`);
  return;
}

const shortDid = did.substr(0, 22);
console.info(`Record written! sending to ${shortDid}...`);

const { status: sendStatus } = await record.send(bob);

if (sendStatus.code !== 202) {
  console.error(`${sendStatus.code} - ${sendStatus.detail}`);
  return;
}

console.info(`Sent to ${shortDid}!`);

Reading a Message to Bob from Alice

const { records, status } = await sdk.dwn.records.query({
  message: {
    filter: {
      protocol: pingerProtocolDefinition.protocol
    },
    dateSort: 'createdDescending'
  }
});

if (status.code !== 200) {
  console.error('Failed to query', status);
  return;
}

for (let record of records) {
  const { author, note } = await record.data.json();
  console.info(`${author.substr(0, 22)}... ${note}`);
}
PreviousHandling files
πŸ—ΊοΈ
πŸš€