accountTokenFor static method
The account token a client passes to the store when it opens the
purchase sheet for customer.
A UUID, because StoreKit's appAccountToken must be one, derived from
the billing customer key rather than being the key: the token travels
through the store and back, and an internal user id has no business
doing that. A receipt carrying another customer's token grants nothing.
Implementation
static String accountTokenFor(Object customer) {
final String key = dvBillingCustomerKey(customer);
final List<int> bytes = sha256
.convert(utf8.encode('dartvel.purchases.account$key'))
.bytes
.sublist(0, 16);
bytes[6] = (bytes[6] & 0x0f) | 0x50;
bytes[8] = (bytes[8] & 0x3f) | 0x80;
final String hex =
bytes.map((int b) => b.toRadixString(16).padLeft(2, '0')).join();
return '${hex.substring(0, 8)}-${hex.substring(8, 12)}-'
'${hex.substring(12, 16)}-${hex.substring(16, 20)}-${hex.substring(20)}';
}