Examples: xdiFront

XDI messages understood by xdiFront

Check if an i-name exists already

Example XDI message to check if =web*markus is available:

$
	$get$a$xsd$boolean
		/
			=web*markus
=web*markus
	$is$a
		=

Example responses:

$true
$false

Example code with XDI4j:

// data we need for the message

String iname = "=web*markus";

// prepare and send XDI message

XDIClient client = new XDIHttpClient("http://xdi.freexri.com/");

MessageEnvelope envelope = MessageEnvelope.newInstance();
Message message = envelope.newMessage(new XRI3Segment("$"));
Operation operation = message.createGetExistsOperation();
Graph operationGraph = operation.createOperationGraph(null);
operationGraph.createStatement(new XRI3Segment(iname));
envelope.getGraph().createStatement(new XRI3Segment(iname), new XRI3Segment("$is$a"), new XRI3Segment("="));

MessageResult result = client.send(envelope, null);
if (result instanceof ErrorMessageResult) throw new RuntimeException(((ErrorMessageResult) result).getErrorString());

// read result

boolean exists = result.getGraph().containsSubject(MessagingConstants.XRI_TRUE);
System.out.println(exists);

Register an i-name

Example XDI message to register =web*markus with password secret and e-mail address markus.sabadello@gmail.com:

$
	$add
		/
			=web*markus
				$password
					"secret"
				+email
					"markus.sabadello@gmail.com"
=web*markus
	$is$a
		=

Example response:

=web*markus
	$is$
		=!91F2.8153.F600.AE24!695b.2ae6.38c1.777c

Example code:

// data we need for the message

String iname = "=web*markus";
String password = "secret";
String email = "markus.sabadello@gmail.com";

// prepare and send XDI message

XDIClient client = new XDIHttpClient("http://xdi.freexri.com/");

MessageEnvelope envelope = MessageEnvelope.newInstance();
Message message = envelope.newMessage(new XRI3Segment("$"));
Operation operation = message.createAddOperation();
Graph operationGraph = operation.createOperationGraph(null);
operationGraph.createStatement(new XRI3Segment(iname), new XRI3Segment("$password"), password);
operationGraph.createStatement(new XRI3Segment(iname), new XRI3Segment("+email"), email);
envelope.getGraph().createStatement(new XRI3Segment(iname), new XRI3Segment("$is$a"), new XRI3Segment("="));

MessageResult result = client.send(envelope, null);
if (result instanceof ErrorMessageResult) throw new RuntimeException(((ErrorMessageResult) result).getErrorString());

// read result

String inumber = Addressing.findReferenceXri(result.getGraph(), new XRI3(iname + "/$is$")).toString();
System.out.println(inumber);

Check if a password is correct

Example message to check if password secret is correct for =web*markus and retrieve account i-number:

=web*markus
	$is$a
		=
	$password
		"secret"
	$get$a$xsd$boolean
		/
			=web*markus
				$password
	$get
		/
			=web*markus
				$is$

Example responses:

$true
=web*markus
	$is$
		=!91F2.8153.F600.AE24!5c85.ae82.f787.9562
$false
=web*markus
	$is$
		=!91F2.8153.F600.AE24!5c85.ae82.f787.9562

Example code with XDI4j:

// data we need for the message

String iname = "=web*markus";
String password = "secret";

// prepare and send XDI message

XDIClient client = new XDIHttpClient("http://xdi.freexri.com/");

MessageEnvelope envelope = MessageEnvelope.newInstance();
Message message = envelope.newMessage(new XRI3Segment(iname));
Operation operation = message.createGetExistsOperation();
Graph operationGraph = operation.createOperationGraph(null);
operationGraph.createStatement(new XRI3Segment(iname), new XRI3Segment("$password"));
envelope.getGraph().createStatement(new XRI3Segment(iname), new XRI3Segment("$is$a"), new XRI3Segment("="));
envelope.getGraph().createStatement(new XRI3Segment(iname), new XRI3Segment("$password"), password);
Operation operation2 = message.createGetOperation();
Graph operationGraph2 = operation2.createOperationGraph(null);
operationGraph2.createStatement(new XRI3Segment(iname), new XRI3Segment("$is$"));

MessageResult result = client.send(envelope, null);
if (result instanceof ErrorMessageResult) throw new RuntimeException(((ErrorMessageResult) result).getErrorString());

// read result

boolean correct = result.getGraph().containsSubject(MessagingConstants.XRI_TRUE);
String inumber = Addressing.findReferenceXri(result.getGraph(), new XRI3(iname + "/$is$")).toString();
System.out.println(correct);
System.out.println(inumber);

Retrieve i-name details

Example message to retrieve account details of an i-name:

=web*markus
	$is$a
		=
	$password
		"secret"
	$get
		/
			=web*markus

Example response:

$
	$is$a
		$$xdi
=web*markus
	$password
		"secret"
	$is$
		=!91F2.8153.F600.AE24!5c85.ae82.f787.9562
	$is$a
		=
	$is
		=web*markus
	$certificate$x.509
		"MIID..."
	$key$public
		"MIIB..."
	$key$private
		"MIIE..."

Example code with XDI4j:

	// data we need for the message

	String iname = "=web*markus";
	String password = "secret";

	// prepare and send XDI message

	XDIClient client = new XDIHttpClient("http://xdi.freexri.com/");

	MessageEnvelope envelope = MessageEnvelope.newInstance();
	Message message = envelope.newMessage(new XRI3Segment(iname));
	Operation operation = message.createGetOperation();
	Graph operationGraph = operation.createOperationGraph(null);
	operationGraph.createStatement(new XRI3Segment(iname));
	envelope.getGraph().createStatement(new XRI3Segment(iname), new XRI3Segment("$is$a"), new XRI3Segment("="));
	envelope.getGraph().createStatement(new XRI3Segment(iname), new XRI3Segment("$password"), password);

	MessageResult result = client.send(envelope, null);
	if (result instanceof ErrorMessageResult) throw new RuntimeException(((ErrorMessageResult) result).getErrorString());

	// read result

	String inumber = Addressing.findReferenceXri(result.getGraph(), new XRI3(iname + "/$is$")).toString();
	String certificate = Addressing.findLiteralData(result.getGraph(), new XRI3(iname + "/$certificate$x.509"));
	String publickey = Addressing.findLiteralData(result.getGraph(), new XRI3(iname + "/$key$public"));
	String privatekey = Addressing.findLiteralData(result.getGraph(), new XRI3(iname + "/$key$private"));
	System.out.println(inumber);
	System.out.println(certificate);
	System.out.println(publickey);
	System.out.println(privatekey);

Store arbitrary data in the i-name's XDI context:

Store full name, city and country:

=web*markus
	$is$a
		=
	$password
		"secret"
	$add
		/
			=web*markus
				+name
					"Markus Sabadello"
				+city
					"Vienna"
				+country
					"AT"

Example response:

(none if successful)

Retrieve arbitrary data from the i-name's XDI context:

Retrieve city and country:

=web*markus
	$is$a
		=
	$password
		"secret"
	$get
		/
			=web*markus
				+city
				+country

Example response:

=web*markus
	+city
		"Vienna"
	+country
		"AT"