Require a Sui One Time Witness when issuing a unique authority

A plain witness proves who can construct a type. A library issuing a unique authority also needs assurance that the defining module cannot construct a second witness.

Check the special witness in the issuance path

The permit module declares a zero-field, non-generic type named after the module in uppercase, with only drop. At publication the initializer receives its instance. A generic library accepting T: drop should run the runtime witness check before issuing its authority.

module example::permit;

public struct PERMIT has drop {}

fun init(witness: PERMIT, _ctx: &mut TxContext) {
    assert!(sui::types::is_one_time_witness(&witness), 0);
}

Consume the witness at the unique operation

Pass the witness by value to the constructor that issues the authority. If an API takes only a borrowed witness, the same value can be borrowed again within the transaction. Test a normal droppable type against the library and ensure it is rejected before any privileged object is created.

Sources