APIOpening an envelope

Opening an envelope

Private box envelopes

		OpenPrivateEnvelope.Done done = new OpenPrivateEnvelope.Done() {
			void onOpenPrivateEnvelopeDone(Record envelope, Reference contentReference) {
				// Called when opening and validating the envelope succeeded
			}

			void onOpenPrivateEnvelopeInvalid(String error) {
				// Called if the envelope object was not found, or does not contain a valid envelope
			}

			void onOpenPrivateEnvelopeFailed(String error) {
				// Called if a store could not be accessed
			}
		};

		new OpenPrivateEnvelope(keyPair, accountWithKey, hash, done);
	
		var done = keyPair.openPrivateEnvelope(accountWithKey, hash);

		done.onDone = function(envelope, contentReference) {
			// Called when opening and validating the envelope succeeded
		};

		done.onInvalid = function(error) {
			// Called if the envelope object was not found, or does not contain a valid envelope
		};

		done.onFailed = function(error) {
			// Called if a store could not be accessed
		};
	
		my ($envelope, $contentReference, $invalidError, $storeError) = $keyPair->openPrivateEnvelope($accountWithKey, $hash);

		if (defined $invalidError) {
			# The envelope object was not found, or does not contain a valid envelope
		} elsif (defined $storeError) {
			# A store could not be accessed
		} else {
			# Opening and validating the envelope succeeded
		}
	

Retrieves, opens, and verifies the private box envelope pointed to by hash on accountWithKey. Upon success, the content reference points to the private data on the account's store, and envelope contains the envelope record.

If envelope retrieval failed with a store error, the operation fails. In this case, the envelope may be opened again later when the stores are available.

If the envelope is incomplete, not properly signed, or not encrypted for the key pair, the operation fails as invalid. In this case, the corresponding box entry should be removed. Opening the same envelope will also fail at a later point in time.

Public box envelopes

		OpenPublicEnvelope.Done done = new OpenPublicEnvelope.Done() {
			void onOpenPublicEnvelopeDone(Record envelope, Hash contentHash) {
				// Called when opening and validating the envelope succeeded
			}

			void onOpenPublicEnvelopeInvalid(String error) {
				// Called if the envelope object was not found, or does not contain a valid envelope
			}

			void onOpenPublicEnvelopeFailed(String error) {
				// Called if a store could not be accessed
			}
		};

		new OpenPublicEnvelope(keyPair, accountWithKey, hash, done);
	
		var done = keyPair.openPublicEnvelope(accountWithKey, hash);

		done.onDone = function(envelope, contentHash) {
			// Called when opening and validating the envelope succeeded
		};

		done.onInvalid = function(error) {
			// Called if the envelope object was not found, or does not contain a valid envelope
		};

		done.onFailed = function(error) {
			// Called if a store could not be accessed
		};
	
		my ($envelope, $contentHash, $invalidError, $storeError) = $keyPair->openPublicEnvelope($accountWithKey, $hash);

		if (defined $invalidError) {
			# The envelope object was not found, or does not contain a valid envelope
		} elsif (defined $storeError) {
			# A store could not be accessed
		} else {
			# Opening and validating the envelope succeeded
		}
	

Retrieves, opens, and verifies the public box envelope pointed to by hash on accountWithKey. Upon success, the contentHash points to the public card on the account's store, and envelope contains the envelope record.

If envelope retrieval failed with a store error, the operation fails. In this case, the envelope may be opened again later when the stores are available.

If the envelope is incomplete, or not properly signed, the operation fails as invalid. Opening the same envelope will also fail at a later point in time.

Message envelopes

Messages envelopes are read and verified by the message box reader.